xonecas.io
8356
Wx

www-xonecas-io / commit 13fd348

light/dark toggle in the header, remembered per browser (1025)

Co-Authored-By: Claude Opus 5.5

Sean Caetano Martin2026-11-08 13fd348264a7ab0d54d5b8a65fa401e35ee94ced parent 08604d8

3 files changed

internal/site/templates/components.html+2−1
@@ -6,7 +6,8 @@
66 <nav class="flex gap-5 font-semibold">
77 {{range $l := list "Overview" "Projects"}}<a href="{{if eq $l "Overview"}}/{{else}}/{{lower $l}}/{{end}}" class="{{if eq $l $}}underline underline-offset-[6px] decoration-[3px]{{else}}no-underline{{end}}">{{$l}}</a>{{end}}
88 </nav>
9- <form action="/projects/" class="w-full sm:w-auto sm:ml-auto"><input name="q" placeholder="Search projects" class="w-full sm:w-80 px-3 py-1.5 border-[1.5px] border-ink rounded-[2px] bg-card text-sm placeholder:text-soft"></form>
9+ <button id="theme" type="button" title="Light or dark" aria-label="Switch between light and dark" class="ml-auto p-1 cursor-pointer hover:text-accent"><svg viewBox="0 0 16 16" width="20" height="20" aria-hidden="true"><circle cx="8" cy="8" r="6.5" fill="none" stroke="currentColor" stroke-width="1.5"/><path d="M8 1.5a6.5 6.5 0 0 1 0 13z" fill="currentColor"/></svg></button>
10+ <form action="/projects/" class="w-full sm:w-auto"><input name="q" placeholder="Search projects" class="w-full sm:w-80 px-3 py-1.5 border-[1.5px] border-ink rounded-[2px] bg-card text-sm placeholder:text-soft"></form>
1011 </header>
1112 {{end}}
1213
internal/site/templates/layout.html+9−0
@@ -7,6 +7,15 @@
77 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
88 <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;600&family=IBM+Plex+Sans+Condensed:wght@400;600;700&family=IBM+Plex+Serif:ital@1&display=swap">
99 <link rel="stylesheet" href="/site.css">
10+<script>/* The saved theme, before the first paint; #theme flips it. With none saved, the system decides. */
11+const root = document.documentElement, mode = () => root.dataset.theme || (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
12+try { if (localStorage.theme) root.dataset.theme = localStorage.theme; } catch {}
13+addEventListener("click", e => {
14+ if (!e.target.closest("#theme")) return;
15+ root.dataset.theme = mode() === "dark" ? "light" : "dark";
16+ try { localStorage.theme = root.dataset.theme; } catch {}
17+});
18+</script>
1019 <script src="/egg.js" defer></script>
1120 <body class="bg-paper text-ink font-sans text-[15.5px] leading-snug">
1221 {{end}}
tickets/1025-need-a-light-dark-toggel.md+17−5
@@ -1,12 +1,24 @@
11 ---
22 id: 1025
3-title: Need a light/dark toggel
4-type: bug
5-status: doing
3+title: Need a light/dark toggle
4+type: feature
5+status: review
66 priority: p2
77 created: 2026-11-08T04:14:52Z
8-updated: 2026-11-08T04:14:56Z
8+updated: 2026-11-08T04:23:05Z
99 source: human
10-moves: 2026-11-08T04:14:56Z inbox doing drag
10+moves: 2026-11-08T04:14:56Z inbox doing drag; 2026-11-08T04:23:05Z doing review agent
11+area: site
1112 ---
1213
14+
15+## Notes
16+
17+- 2026-11-08 04:23Z (agent): Done. A theme button (half-filled circle) sits in the header on every page, left of the search box. Clicking it switches between light and dark from what is showing, and remembers the choice in localStorage across pages and visits. Until it is clicked, the site follows the system setting as before. Fixed the title typo 'toggel'.
18+
19+ - layout.html: a small inline script in <head> applies the saved theme before the first paint (no flash) and handles the click. It sets data-theme on <html>, which site.css already supported.
20+ - components.html (nav): the button. The search form lost its own sm:ml-auto; the button's ml-auto pushes both right.
21+
22+ CHECKED: go vet, go test pass. Rebuilt. agent-browser: with nothing saved, no data-theme and the light background (system light). Click: data-theme=dark, saved, background #15140f. Next page (/projects/) loads dark. Click again: light, saved. Screenshots: dark /projects at 1280px; light at 390px phone width (button on the first row, search on its own row).
23+
24+ NOT CHECKED: going back to 'follow the system' after a click (two states only; clearing site data resets it). No-JS: the button shows but does nothing.