patx/gitman

Add combined account settings, saved themes, and repository list cards

Commit b25eeb2 · patx · Nov 3 at 9:04PM

Changeset
b25eeb22c7315d89e78e035079081e6684a5a604
Parents
fa1604ba3b6f77fd361e77096f6ee13f18907a45

View source at this commit

Comments

No comments yet.

Log in to comment

Diff

diff --git a/README.md b/README.md
index 306a87c..c10cb00 100644
--- a/README.md
+++ b/README.md
@@ -103,7 +103,9 @@ GitMan is licensed under the BSD 3-Clause License. See [LICENSE](https://gitman.
 Sign-in sessions persist for 14 days, with a fixed expiry checked by the server.
 Existing signed sessions upgrade on their next visit.
 
-Edit profile includes a Change password dialog. Changes require the current
+Settings contains separate profile and password cards. Profile settings include
+a saved Auto, Light, or Dark theme preference; Auto follows the system appearance
+and is the default for new and existing accounts. Password changes require the current
 password, validate confirmation, and invalidate other browser sessions. Git HTTPS
 uses the new password immediately. Existing sessions survive upgrading until their
 account changes its password. Password changes use CSRF protection and failed-attempt
diff --git a/app.py b/app.py
index 395b19b..ecb7b24 100644
--- a/app.py
+++ b/app.py
@@ -542,6 +542,7 @@ def init_db():
             CREATE INDEX IF NOT EXISTS idx_auth_rate_limits_expiry ON auth_rate_limits(reset_at, blocked_until);
             """
         )
+        conn.execute("BEGIN IMMEDIATE")
         ensure_user_profile_columns(conn)
         ensure_repository_collaboration_columns(conn)
         ensure_repository_pages_columns(conn)
@@ -556,6 +557,7 @@ def ensure_user_profile_columns(conn):
     columns = {row["name"] for row in conn.execute("PRAGMA table_info(users)")}
     profile_columns = {
         "session_version": "ALTER TABLE users ADD COLUMN session_version INTEGER NOT NULL DEFAULT 0",
+        "theme_preference": "ALTER TABLE users ADD COLUMN theme_preference TEXT NOT NULL DEFAULT 'auto' CHECK (theme_preference IN ('auto', 'light', 'dark'))",
         "display_name": "ALTER TABLE users ADD COLUMN display_name TEXT NOT NULL DEFAULT ''",
         "bio": "ALTER TABLE users ADD COLUMN bio TEXT NOT NULL DEFAULT ''",
         "website": "ALTER TABLE users ADD COLUMN website TEXT NOT NULL DEFAULT ''",
@@ -1028,6 +1030,8 @@ def add_security_headers():
 
 def render(template_name, **context):
     context.setdefault("user", current_user())
+    if context["user"] is not None:
+        response.set_header("Cache-Control", "no-store")
     context.setdefault("error", None)
     context.setdefault("notice", None)
     context.setdefault("csrf_field", csrf_field)
@@ -1947,6 +1951,7 @@ def profile_form_values(form, fallback=None):
         "bio": (form.get("bio", fallback.get("bio", "")) or "").strip()[:1000],
         "website": (form.get("website", fallback.get("website", "")) or "").strip(),
         "created_at": fallback.get("created_at", ""),
+        "theme_preference": (form.get("theme_preference", fallback.get("theme_preference", "auto")) or "auto").strip(),
     }
 
 
@@ -5173,6 +5178,7 @@ def logout():
     redirect("/")
 
 
[email protected]("/settings", method=["GET", "POST"])
 @app.route("/settings/profile", method=["GET", "POST"])
 def edit_profile():
     user = require_login()
@@ -5181,15 +5187,17 @@ def edit_profile():
 
     values = profile_form_values(request.forms, user)
     try:
+        if values["theme_preference"] not in {"auto", "light", "dark"}:
+            raise ValueError("Choose Auto, Light, or Dark for your theme.")
         values["website"] = normalize_website(values["website"])
         with db_connect() as conn:
             conn.execute(
                 """
                 UPDATE users
-                SET display_name = ?, bio = ?, website = ?
+                SET display_name = ?, bio = ?, website = ?, theme_preference = ?
                 WHERE id = ?
                 """,
-                (values["display_name"], values["bio"], values["website"], user["id"]),
+                (values["display_name"], values["bio"], values["website"], values["theme_preference"], user["id"]),
             )
         refreshed = get_user_by_id(user["id"])
         request.environ["gitman.user"] = refreshed
@@ -5209,7 +5217,7 @@ def change_password():
     confirmation = request.forms.get("confirm_password", "")
     def invalid(message, status=400):
         response.status = status
-        return render_user_profile(user, password_error=message)
+        return render("edit_profile.tpl", profile=user, password_error=message)
     if len(current) > 1024 or not verify_password(current, user["password_hash"]):
         record_auth_failure("password-change", identifier)
         return invalid("Current password is incorrect.")
@@ -5231,7 +5239,7 @@ def change_password():
     refreshed = get_user_by_id(user["id"])
     request.environ["gitman.user"] = refreshed
     login_user(refreshed)
-    return render_user_profile(refreshed, notice="Password changed. Other browser sessions are signed out.")
+    return render("edit_profile.tpl", profile=refreshed, notice="Password changed. Other browser sessions are signed out.")
 
 
 @app.route("/new", method=["GET", "POST"])
diff --git a/static/profile.js b/static/profile.js
deleted file mode 100644
index bb52a2a..0000000
--- a/static/profile.js
+++ /dev/null
@@ -1,14 +0,0 @@
-(() => {
-  const dialog = document.getElementById('password-dialog');
-  const open = document.getElementById('change-password-open');
-  if (!dialog || !open) return;
-  open.addEventListener('click', () => dialog.showModal());
-  document.getElementById('change-password-cancel').addEventListener('click', () => dialog.close());
-  dialog.addEventListener('close', () => {
-    dialog.querySelector('form').reset();
-    const error = dialog.querySelector('[role="alert"]');
-    if (error) error.remove();
-    open.focus();
-  });
-  if (dialog.dataset.reopen === 'true') dialog.showModal();
-})();
diff --git a/static/styles.css b/static/styles.css
index 2663217..b180b7f 100644
--- a/static/styles.css
+++ b/static/styles.css
@@ -23,7 +23,7 @@ html {
 
 
 @media (prefers-color-scheme: dark) {
-  :root {
+  :root:not([data-theme="light"]) {
     color-scheme: dark;
     --page-bg: #000000;
     --ink: #ffffff;
@@ -37,6 +37,19 @@ html {
   }
 }
 
+:root[data-theme="dark"] {
+  color-scheme: dark;
+  --page-bg: #000000;
+  --ink: #ffffff;
+  --text: #b3b3b3;
+  --muted: #999999;
+  --chip: #333333;
+  --press: #e2e2e2;
+  --surface: #161616;
+  --surface-border: #262626;
+  --code-bg: #1f1f1f;
+}
+
 body {
   display: flex;
   flex-direction: column;
@@ -314,7 +327,7 @@ th { color: var(--ink); font-weight: 700; }
   text-decoration: underline;
 }
 
-.eyebrow, .muted, .empty, .issue-list span { color: var(--muted); }
+.eyebrow, .muted, .empty, .issue-list .muted { color: var(--muted); }
 .eyebrow { font-size: .875rem; }
 
 .repo-list, .clean-list, .commit-list, .file-list, .issue-list, .comment-list, .activity-feed {
@@ -325,13 +338,8 @@ th { color: var(--ink); font-weight: 700; }
   list-style: none;
 }
 .repo-list { gap: 1rem; }
-.commit-list { gap: 1.25rem; }
+.card-list { gap: 1rem; }
 .comment-list { gap: 1rem; }
-.commit-list li > div > :last-child { margin-bottom: 0; }
-.commit-list li strong, .commit-list li small { display: block; }
-.commit-list li p { margin-top: .5rem; }
-.commit-list li, .file-list li { display: grid; grid-template-columns: 8rem 1fr; gap: 1rem; }
-.commit-list li > code, .file-list li > code { justify-self: start; }
 
 .meta-list { display: grid; grid-template-columns: 8rem 1fr; gap: .35rem 1rem; }
 .meta-list dt { color: var(--muted); }
@@ -511,21 +519,11 @@ th { color: var(--ink); font-weight: 700; }
 .danger-zone { margin-top: 1rem; padding-top: 2rem; border-top: 1px solid var(--surface-border); }
 .danger-zone h2 { margin-top: 0; }
 
-.password-dialog {
-  width: min(28rem, calc(100% - 2rem));
-  max-height: calc(100dvh - 2rem);
-  overflow: auto;
-  padding: 1.5rem;
-  border: 1px solid var(--surface-border);
-  border-radius: 8px;
-  color: var(--text);
-  background: var(--surface);
-}
-.password-dialog::backdrop { background: rgb(0 0 0 / .6); }
-.password-dialog h2 { font-size: 1.25rem; margin-bottom: 1rem; }
-.password-dialog .muted { font-size: .875rem; }
-.password-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .75rem; }
-.password-dialog form { margin-bottom: 0; }
+.settings-page { max-width: 42rem; }
+.settings-cards { display: grid; gap: 1.5rem; margin-top: 1.5rem; }
+.settings-card > :last-child { margin-bottom: 0; }
+.settings-card > form { margin-top: 1.25rem; }
+.settings-back { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; margin-top: 1.5rem; }
 
 .mention-menu {
   position: fixed;
@@ -575,7 +573,7 @@ th { color: var(--ink); font-weight: 700; }
   text-align: center;
 }
 .notification-feed form { display: block; }
-.feed-card, .comment {
+.feed-card, .comment, .settings-card, .reference-card {
   display: block;
   width: 100%;
   padding: 1.25rem;
@@ -588,9 +586,9 @@ th { color: var(--ink); font-weight: 700; }
   line-height: 1.6;
   overflow-wrap: anywhere;
 }
-.feed-card > span { display: block; margin: 0; }
-.feed-card > span + span { margin-top: .5rem; }
-.feed-card .activity-title { color: var(--ink); }
+.feed-card > span, .reference-main > span { display: block; margin: 0; }
+.feed-card > span + span, .reference-main > span + span { margin-top: .5rem; }
+.feed-card .activity-title, .reference-card .activity-title { color: var(--ink); }
 .notification-card.notification-unread { background: var(--code-bg); }
 .feed-card:hover, .feed-card:active {
   background: var(--chip);
@@ -598,12 +596,20 @@ th { color: var(--ink); font-weight: 700; }
   text-decoration: none;
 }
 .feed-card:focus-visible { outline-offset: 3px; }
+.reference-card { position: relative; }
+.reference-card:hover { background: var(--chip); }
+.reference-main { display: block; }
+.reference-main:hover { color: inherit; text-decoration: none; }
+.reference-main::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
+.reference-main:focus-visible { outline: none; }
+.reference-main:focus-visible::after { outline: 2px solid var(--ink); outline-offset: 3px; }
+.reference-actions { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin-top: 1rem; }
+.reference-actions a { position: relative; z-index: 1; }
 .mention-option:hover small, .mention-option.active small { color: inherit; }
 
 @media (max-width: 760px) {
   .repo-search, .repo-search-input { width: 100%; }
   .repo-search-menu { left: 0; right: auto; width: 100%; }
-  .commit-list li, .file-list li { grid-template-columns: 1fr; }
   .repo-header { align-items: flex-start; }
 }
 
diff --git a/templates/base.tpl b/templates/base.tpl
index de427db..f0fce47 100644
--- a/templates/base.tpl
+++ b/templates/base.tpl
@@ -1,17 +1,26 @@
+% theme = user["theme_preference"] if user else "auto"
 <!doctype html>
-<html lang="en">
+<html lang="en" data-theme="{{theme}}">
 <head>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">
-  <meta name="color-scheme" content="light dark">
-  <meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
-  <meta name="theme-color" content="#000000" media="(prefers-color-scheme: dark)">
+  <meta name="color-scheme" content="{{'light dark' if theme == 'auto' else theme}}">
+  % if theme == 'auto':
+    <meta name="theme-color" content="#ffffff" media="(prefers-color-scheme: light)">
+    <meta name="theme-color" content="#000000" media="(prefers-color-scheme: dark)">
+  % else:
+    <meta name="theme-color" content="{{'#000000' if theme == 'dark' else '#ffffff'}}">
+  % end
   <meta name="description" content="GitMan: free Git repository hosting for open source software.">
   <title>{{(title + " · GitMan") if title else "GitMan"}}</title>
   <link rel="icon" type="image/svg+xml" href="/static/git.svg">
-  <link rel="stylesheet" href="/static/vendor/highlight.js/github.min.css">
-  <link rel="stylesheet" href="/static/vendor/highlight.js/github-dark.min.css" media="(prefers-color-scheme: dark)">
-  <link rel="stylesheet" href="/static/styles.css?v=15">
+  % if theme != 'dark':
+    <link rel="stylesheet" href="/static/vendor/highlight.js/github.min.css">
+  % end
+  % if theme != 'light':
+    <link rel="stylesheet" href="/static/vendor/highlight.js/github-dark.min.css"{{!' media="(prefers-color-scheme: dark)"' if theme == 'auto' else ''}}>
+  % end
+  <link rel="stylesheet" href="/static/styles.css?v=16">
 </head>
 <body>
   <header class="site-header">
diff --git a/templates/branches.tpl b/templates/branches.tpl
index 3c677dd..a60ca02 100644
--- a/templates/branches.tpl
+++ b/templates/branches.tpl
@@ -14,19 +14,10 @@
 
 <section class="panel">
   % if branches:
-    <ul class="commit-list" data-paginated-list>
+    <ul class="commit-list card-list" data-paginated-list>
       % for branch in branches:
         <li>
-          <code>{{branch["name"]}}</code>
-          <div>
-            <strong><a href="/{{repo['owner_username']}}/{{repo['name']}}/commits/{{branch['short_node']}}">{{branch["short_node"]}}</a></strong>
-            <small>commit {{branch["short_node"]}} · {{branch["date"]}}</small>
-            <p>{{branch["summary"]}}
-              <small><a href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/src', branch, True)}}">Browse code</a> · 
-                <a href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/commits', branch, True)}}">Commits</a> · 
-                <a href="/{{repo['owner_username']}}/{{repo['name']}}/archive/{{branch['short_node']}}.zip">Archive</a></small>
-            </p>
-          </div>
+          % include("reference_card.tpl", reference=branch, repo=repo)
         </li>
       % end
     </ul>
diff --git a/templates/commits.tpl b/templates/commits.tpl
index 9f502be..f285194 100644
--- a/templates/commits.tpl
+++ b/templates/commits.tpl
@@ -13,14 +13,13 @@
 
 <section class="panel">
   % if commits:
-    <ul class="commit-list" data-paginated-list>
+    <ul class="commit-list card-list" data-paginated-list>
       % for commit in commits:
         <li>
-          <code><a href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/commits/' + commit['node'], selected_ref)}}">{{commit["short_node"]}}</a></code>
-          <div>
-            <strong>{{commit["summary"]}}</strong>
-            <small>{{commit["author"]}} · {{commit["date"]}}</small>
-          </div>
+          <a class="feed-card" href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/commits/' + commit['node'], selected_ref)}}">
+            <span class="activity-title"><strong>{{commit['summary']}}</strong></span>
+            <span class="muted"><code>{{commit['short_node']}}</code> · {{commit['author']}} · {{commit['date']}}</span>
+          </a>
         </li>
       % end
     </ul>
diff --git a/templates/edit_profile.tpl b/templates/edit_profile.tpl
index c04ae87..e81df14 100644
--- a/templates/edit_profile.tpl
+++ b/templates/edit_profile.tpl
@@ -1,22 +1,62 @@
-% rebase("base.tpl", title="Edit profile", user=user, error=error, notice=notice)
+% rebase("base.tpl", title="Settings", user=user, error=error, notice=notice)
 
-<section class="auth-card wide">
-  <h1>Edit profile</h1>
-  <form method="post">
-    {{!csrf_field()}}
-    <label>
-      Display name
-      <input name="display_name" value="{{profile['display_name']}}" maxlength="80">
-    </label>
-    <label>
-      Bio
-      <textarea name="bio" rows="6" maxlength="1000">{{profile["bio"]}}</textarea>
-    </label>
-    <label>
-      Website
-      <input name="website" value="{{profile['website']}}" placeholder="https://example.com" maxlength="255">
-    </label>
-    <button class="button" type="submit">Save profile</button>
-  </form>
-  <p class="muted"><a href="/{{profile['username']}}"><- Back</a></p>
+<section class="settings-page">
+  <h1>Settings</h1>
+  <div class="settings-cards">
+    <section class="settings-card" aria-labelledby="profile-settings-title">
+      <h2 id="profile-settings-title">Profile settings</h2>
+      <form method="post" action="/settings">
+        {{!csrf_field()}}
+        <label>
+          Display name
+          <input name="display_name" value="{{profile['display_name']}}" maxlength="80">
+        </label>
+        <label>
+          Bio
+          <textarea name="bio" rows="6" maxlength="1000">{{profile['bio']}}</textarea>
+        </label>
+        <label>
+          Website
+          <input name="website" value="{{profile['website']}}" placeholder="https://example.com" maxlength="255">
+        </label>
+        <label>
+          Theme
+          <select name="theme_preference">
+            % for value, label in [('auto', 'Auto (use system setting)'), ('light', 'Light'), ('dark', 'Dark')]:
+              <option value="{{value}}" {{'selected' if profile['theme_preference'] == value else ''}}>{{label}}</option>
+            % end
+          </select>
+        </label>
+        <button class="button" type="submit">Save profile</button>
+      </form>
+    </section>
+    <section class="settings-card" aria-labelledby="password-settings-title">
+      <h2 id="password-settings-title">Change password</h2>
+      % if get('password_error'):
+        <p class="alert" role="alert">{{password_error}}</p>
+      % end
+      <form method="post" action="/settings/password">
+        {{!csrf_field()}}
+        <input type="text" name="username" value="{{user['username']}}" autocomplete="username" hidden>
+        <label>
+          Current password
+          <input type="password" name="current_password" autocomplete="current-password" maxlength="1024" required>
+        </label>
+        <label>
+          New password
+          <input type="password" name="new_password" autocomplete="new-password" minlength="8" maxlength="1024" required aria-describedby="password-hint">
+        </label>
+        <label>
+          Confirm new password
+          <input type="password" name="confirm_password" autocomplete="new-password" minlength="8" maxlength="1024" required>
+        </label>
+        <p class="muted" id="password-hint">At least 8 characters. Other browser sessions will be signed out.</p>
+        <button class="button" type="submit">Change password</button>
+      </form>
+    </section>
+  </div>
+  <nav class="settings-back" aria-label="Account actions">
+    <a href="/{{profile['username']}}">Back to profile</a>
+    <a href="/logout">Log out</a>
+  </nav>
 </section>
diff --git a/templates/issues.tpl b/templates/issues.tpl
index d482276..0849714 100644
--- a/templates/issues.tpl
+++ b/templates/issues.tpl
@@ -36,10 +36,13 @@
   </div>
   <div id="issue-search-results" data-live-search-results aria-live="polite">
     % if issues:
-      <ul class="issue-list" data-paginated-list>
+      <ul class="issue-list card-list" data-paginated-list>
         % for issue in issues:
           <li>
-            <a href="/{{repo['owner_username']}}/{{repo['name']}}/issues/{{issue['number']}}">#{{issue["number"]}} {{issue["title"]}}</a> <span>({{issue["status"]}})</span>
+            <a class="feed-card" href="/{{repo['owner_username']}}/{{repo['name']}}/issues/{{issue['number']}}">
+              <span class="activity-title"><strong>#{{issue['number']}} {{issue['title']}}</strong></span>
+              <span class="muted">{{issue['status']}}</span>
+            </a>
           </li>
         % end
       </ul>
diff --git a/templates/password_dialog.tpl b/templates/password_dialog.tpl
deleted file mode 100644
index 0b5da4c..0000000
--- a/templates/password_dialog.tpl
+++ /dev/null
@@ -1,25 +0,0 @@
-<dialog id="password-dialog" class="password-dialog" aria-labelledby="password-title" data-reopen="{{'true' if get('password_error') else 'false'}}">
-  <h2 id="password-title">Change password</h2>
-  <form method="post" action="/settings/password">
-    {{!csrf_field()}}
-    <input type="text" name="username" value="{{user['username']}}" autocomplete="username" hidden>
-    % if get('password_error'):
-      <p class="alert" role="alert">{{password_error}}</p>
-    % end
-    <label>Current password
-      <input type="password" name="current_password" autocomplete="current-password" maxlength="1024" required autofocus>
-    </label>
-    <label>New password
-      <input type="password" name="new_password" autocomplete="new-password" minlength="8" maxlength="1024" required aria-describedby="password-hint">
-    </label>
-    <label>Confirm new password
-      <input type="password" name="confirm_password" autocomplete="new-password" minlength="8" maxlength="1024" required>
-    </label>
-    <p class="muted" id="password-hint">At least 8 characters. Other browser sessions will be signed out.</p>
-    <div class="password-actions">
-      <button type="button" id="change-password-cancel">Cancel</button>
-      <button type="submit">Change password</button>
-    </div>
-  </form>
-</dialog>
-<script src="/static/profile.js?v=1" defer></script>
diff --git a/templates/profile.tpl b/templates/profile.tpl
index 84449fa..19d0633 100644
--- a/templates/profile.tpl
+++ b/templates/profile.tpl
@@ -12,7 +12,7 @@
   <p class="muted"><small>
     Joined {{profile_user["created_at"]}}
     % if is_self:
-      <a class="button-link" href="/settings/profile">Edit profile</a> &middot; <button class="link-button" type="button" id="change-password-open">Change password</button> &middot; <a class="button-link" href="/logout">Log out</a>
+      <a class="button-link" href="/settings">Settings</a>
     % end
   </small></p>
   % if profile_user["bio"]:
@@ -51,7 +51,3 @@
     % include("pagination.tpl", pagination=pagination)
   % end
 </section>
-
-% if is_self:
-  % include("password_dialog.tpl")
-% end
diff --git a/templates/pull_requests.tpl b/templates/pull_requests.tpl
index b100574..890b40f 100644
--- a/templates/pull_requests.tpl
+++ b/templates/pull_requests.tpl
@@ -37,11 +37,13 @@
   </div>
   <div id="pull-request-search-results" data-live-search-results aria-live="polite">
     % if pull_requests:
-      <ul class="issue-list" data-paginated-list>
+      <ul class="issue-list card-list" data-paginated-list>
         % for pr in pull_requests:
           <li>
-            <a href="/{{repo['owner_username']}}/{{repo['name']}}/pulls/{{pr['number']}}">#{{pr["number"]}} {{pr["title"]}}</a>
-            <span>({{pr["status"]}} from {{pr["source_owner_username"]}}/{{pr["source_repo_name"]}} {{format_ref_label(pr["source_ref_type"], pr["source_ref_name"])}} into {{format_ref_label(pr["target_ref_type"], pr["target_ref_name"])}})</span>
+            <a class="feed-card" href="/{{repo['owner_username']}}/{{repo['name']}}/pulls/{{pr['number']}}">
+              <span class="activity-title"><strong>#{{pr['number']}} {{pr['title']}}</strong></span>
+              <span class="muted">{{pr['status']}} · from {{pr['source_owner_username']}}/{{pr['source_repo_name']}} {{format_ref_label(pr['source_ref_type'], pr['source_ref_name'])}} into {{format_ref_label(pr['target_ref_type'], pr['target_ref_name'])}}</span>
+            </a>
           </li>
         % end
       </ul>
diff --git a/templates/reference_card.tpl b/templates/reference_card.tpl
new file mode 100644
index 0000000..d4a4837
--- /dev/null
+++ b/templates/reference_card.tpl
@@ -0,0 +1,12 @@
+<article class="reference-card">
+  <a class="reference-main" href="/{{repo['owner_username']}}/{{repo['name']}}/commits/{{reference['short_node']}}">
+    <span class="activity-title"><strong>{{reference['name']}}</strong></span>
+    <span class="activity-detail">{{reference['summary']}}</span>
+    <span class="muted"><code>{{reference['short_node']}}</code> · {{reference['date']}}</span>
+  </a>
+  <nav class="reference-actions" aria-label="Actions for {{reference['name']}}">
+    <a href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/src', reference, True)}}">Browse code</a>
+    <a href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/commits', reference, True)}}">Commits</a>
+    <a href="/{{repo['owner_username']}}/{{repo['name']}}/archive/{{reference['short_node']}}.zip">Archive</a>
+  </nav>
+</article>
diff --git a/templates/source.tpl b/templates/source.tpl
index 08d8894..c86c57d 100644
--- a/templates/source.tpl
+++ b/templates/source.tpl
@@ -23,15 +23,13 @@
 
 <section class="panel">
   % if entries:
-    <ul class="file-list">
+    <ul class="file-list card-list">
       % for entry in entries:
         <li>
-          <code>{{"dir" if entry["type"] == "dir" else "file"}}</code>
-          <div>
-            <a href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/src/' + quote_path(entry['path']), selected_ref)}}">
-              <strong>{{entry["name"]}}{{"/" if entry["type"] == "dir" else ""}}</strong>
-            </a>
-          </div>
+          <a class="feed-card" href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/src/' + quote_path(entry['path']), selected_ref)}}">
+            <span class="activity-title"><strong>{{entry['name']}}{{'/' if entry['type'] == 'dir' else ''}}</strong></span>
+            <span class="muted">{{'Directory' if entry['type'] == 'dir' else 'File'}}</span>
+          </a>
         </li>
       % end
     </ul>
diff --git a/templates/tags.tpl b/templates/tags.tpl
index 5c78f54..d6b7903 100644
--- a/templates/tags.tpl
+++ b/templates/tags.tpl
@@ -14,19 +14,10 @@
 
 <section class="panel">
   % if tags:
-    <ul class="commit-list" data-paginated-list>
+    <ul class="commit-list card-list" data-paginated-list>
       % for tag in tags:
         <li>
-          <code>{{tag["name"]}}</code>
-          <div>
-            <strong><a href="/{{repo['owner_username']}}/{{repo['name']}}/commits/{{tag['short_node']}}">{{tag["short_node"]}}</a></strong>
-            <small>commit {{tag["short_node"]}} · {{tag["date"]}}</small>
-            <p>{{tag["summary"]}}
-              <small><a href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/src', tag, True)}}">Browse code</a> ·
-              <a href="{{url_with_ref('/' + repo['owner_username'] + '/' + repo['name'] + '/commits', tag, True)}}">Commits</a> · 
-              <a href="/{{repo['owner_username']}}/{{repo['name']}}/archive/{{tag['short_node']}}.zip">Archive</a></small>
-            </p>
-          </div>
+          % include("reference_card.tpl", reference=tag, repo=repo)
         </li>
       % end
     </ul>
diff --git a/tests/test_app.py b/tests/test_app.py
index f04e4ce..19207fc 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -7,6 +7,7 @@ from io import BytesIO, StringIO
 import os
 import re
 import shutil
+import sqlite3
 import subprocess
 import sys
 import tempfile
@@ -1601,20 +1602,20 @@ def test_repo_branch_and_tag_pages_paginate_refs(isolated_app, monkeypatch):
     tags_first = client.get("/alice/many/tags")
     tags_second = client.get("/alice/many/tags?page=2")
 
-    branch_first_codes = re.findall(r"<code>(?:main|topic\d\d)</code>", branches_first.text)
-    branch_second_codes = re.findall(r"<code>(?:main|topic\d\d)</code>", branches_second.text)
-    tag_first_codes = re.findall(r"<code>v\d\d</code>", tags_first.text)
-    tag_second_codes = re.findall(r"<code>v\d\d</code>", tags_second.text)
+    branch_first_names = re.findall(r"<strong>(main|topic\d\d)</strong>", branches_first.text)
+    branch_second_names = re.findall(r"<strong>(main|topic\d\d)</strong>", branches_second.text)
+    tag_first_names = re.findall(r"<strong>(v\d\d)</strong>", tags_first.text)
+    tag_second_names = re.findall(r"<strong>(v\d\d)</strong>", tags_second.text)
 
-    assert len(branch_first_codes) == 2
-    assert len(branch_second_codes) == 2
-    assert set(branch_first_codes).isdisjoint(branch_second_codes)
+    assert len(branch_first_names) == 2
+    assert len(branch_second_names) == 2
+    assert set(branch_first_names).isdisjoint(branch_second_names)
     assert 'data-next-url="/alice/many/branches?page=2"' in branches_first.text
     assert ">Next</a>" not in branches_first.text
     assert "Showing" not in branches_first.text
-    assert len(tag_first_codes) == 2
-    assert len(tag_second_codes) == 2
-    assert set(tag_first_codes).isdisjoint(tag_second_codes)
+    assert len(tag_first_names) == 2
+    assert len(tag_second_names) == 2
+    assert set(tag_first_names).isdisjoint(tag_second_names)
     assert 'data-next-url="/alice/many/tags?page=2"' in tags_first.text
     assert ">Next</a>" not in tags_first.text
     assert "Showing" not in tags_first.text
@@ -2714,15 +2715,19 @@ def test_change_password_revokes_other_sessions_and_git_credentials(isolated_app
     legacy.cookies['session'] = cookie_encode(('session', str(owner['id'])), gitman.SECRET_KEY).decode()
     assert legacy.get('/settings/profile').status_code == 200
     profile = client.get('/alice').text
-    assert 'id="change-password-open"' in profile
+    assert 'href="/settings">Settings</a>' in profile
+    assert 'href="/logout"' not in profile
     assert profile.index('aria-label="Notifications"') < profile.index('aria-label="New repository"') < profile.index('aria-label="Profile"')
-    assert 'id="change-password-open"' not in WsgiClient(isolated_app.app).get('/alice').text
-    assert 'id="change-password-open"' not in client.get('/settings/profile').text
+    assert 'href="/settings">Settings</a>' not in WsgiClient(isolated_app.app).get('/alice').text
+    settings = client.get('/settings').text
+    assert '<h1>Settings</h1>' in settings
+    assert 'href="/logout"' in settings
+    assert 'action="/settings/password"' in settings
     result = client.post('/settings/password', {'current_password': 'correct horse battery staple',
         'new_password': 'a different secure password', 'confirm_password': 'a different secure password'})
     assert result.status_code == 200 and 'Password changed.' in result.text
-    assert 'id="change-password-open"' in result.text
-    assert '<h1>Edit profile</h1>' not in result.text
+    assert '<h1>Settings</h1>' in result.text
+    assert 'action="/settings/password"' in result.text
     assert client.get('/settings/profile').status_code == 200
     for browser in (other, legacy):
         assert browser.get('/settings/profile').status_code == 303
@@ -2748,9 +2753,9 @@ def test_change_password_rejects_invalid_input_without_changing_credentials(isol
     client.get('/settings/profile')
     result = client.post('/settings/password', {'current_password':current, 'new_password':new, 'confirm_password':confirmation})
     assert result.status_code == 400
-    assert 'data-reopen="true"' in result.text
-    assert 'id="change-password-open"' in result.text
-    assert '<h1>Edit profile</h1>' not in result.text
+    assert 'role="alert"' in result.text
+    assert '<h1>Settings</h1>' in result.text
+    assert 'action="/settings/password"' in result.text
     assert 'value="'+new+'"' not in result.text
     assert isolated_app.get_user_by_id(owner['id'])['password_hash'] == owner['password_hash']
 
@@ -3129,3 +3134,61 @@ def test_new_backdated_commits_are_unread_after_mark_all_read(isolated_app, monk
     fields = notification_read_fields(client.get('/-/notifications'))
     assert client.post('/-/notifications/read', fields).status_code == 303
     assert json.loads(client.get('/-/notifications/unread').text)['unread_count'] == 0
+
+
+def test_theme_preference_migration_defaults_existing_and_new_accounts_to_auto():
+    with sqlite3.connect(":memory:") as conn:
+        conn.row_factory = sqlite3.Row
+        conn.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, username TEXT NOT NULL)")
+        conn.execute("INSERT INTO users (username) VALUES ('existing')")
+        gitman.ensure_user_profile_columns(conn)
+        assert conn.execute("SELECT theme_preference FROM users WHERE username='existing'").fetchone()[0] == 'auto'
+        conn.execute("INSERT INTO users (username) VALUES ('new')")
+        assert conn.execute("SELECT theme_preference FROM users WHERE username='new'").fetchone()[0] == 'auto'
+        conn.execute("UPDATE users SET theme_preference='dark' WHERE username='existing'")
+        gitman.ensure_user_profile_columns(conn)
+        assert conn.execute("SELECT theme_preference FROM users WHERE username='existing'").fetchone()[0] == 'dark'
+
+
[email protected]('theme', ['light', 'dark', 'auto'])
+def test_settings_save_theme_across_pages_devices_and_accounts(isolated_app, theme):
+    alice = create_user('alice')
+    create_user('bob')
+    client = WsgiClient(isolated_app.app)
+    login_client(client, 'alice')
+    assert isolated_app.get_user_by_id(alice['id'])['theme_preference'] == 'auto'
+    saved = client.post('/settings', {'display_name': 'Alice', 'theme_preference': theme})
+    assert saved.status_code == 200
+    assert saved.header('Cache-Control') == 'no-store'
+    assert f'data-theme="{theme}"' in saved.text
+    assert isolated_app.get_user_by_id(alice['id'])['theme_preference'] == theme
+    device = WsgiClient(isolated_app.app)
+    login_client(device, 'alice')
+    page = device.get('/bob').text
+    assert f'data-theme="{theme}"' in page
+    if theme == 'light':
+        assert 'github-dark.min.css' not in page
+    elif theme == 'dark':
+        assert 'github.min.css' not in page
+        assert 'github-dark.min.css" media=' not in page
+    else:
+        assert 'github-dark.min.css" media="(prefers-color-scheme: dark)"' in page
+    assert 'data-theme="auto"' in WsgiClient(isolated_app.app).get('/alice').text
+    assert isolated_app.get_user_by_username('bob')['theme_preference'] == 'auto'
+    # Legacy profile saves without a theme preserve the account's choice.
+    client.post('/settings/profile', {'bio': 'Updated bio'})
+    assert isolated_app.get_user_by_id(alice['id'])['theme_preference'] == theme
+
+
+def test_settings_reject_invalid_theme_and_require_authentication_and_csrf(isolated_app):
+    alice = create_user('alice')
+    guest = WsgiClient(isolated_app.app)
+    assert guest.get('/settings').location_path == '/login?next=/settings'
+    client = WsgiClient(isolated_app.app)
+    login_client(client, 'alice')
+    rejected = client.post('/settings', {'display_name': 'Must not save', 'theme_preference': 'neon'})
+    assert 'Choose Auto, Light, or Dark' in rejected.text
+    user = isolated_app.get_user_by_id(alice['id'])
+    assert user['theme_preference'] == 'auto' and user['display_name'] == alice['display_name']
+    assert client.post('/settings', {'theme_preference': 'dark', '_csrf_token': 'invalid'}).status_code == 403
+    assert isolated_app.get_user_by_id(alice['id'])['theme_preference'] == 'auto'