feat: HTML page shell with controls bar, timezone picker, and theme toggle

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-02 18:34:04 -05:00
parent 267470d18a
commit d3a7d083a7
2 changed files with 165 additions and 0 deletions

87
src/render/page.ts Normal file
View File

@@ -0,0 +1,87 @@
import { getCSS } from "../style/css";
import { TIMEZONE_CONFIG } from "../time/zones";
import { getWeekBounds, getAdjacentWeeks } from "../time/week";
import type { Preferences, TimezoneKey } from "../types";
export function renderPage(title: string, bodyContent: string, prefs: Preferences): string {
const css = getCSS();
const weekBounds = getWeekBounds(prefs.week, prefs.tz);
const { prev, next } = getAdjacentWeeks(prefs.week);
const tzLinks = (Object.entries(TIMEZONE_CONFIG) as [TimezoneKey, { iana: string; label: string }][])
.map(([key, config]) => {
const isCurrent = key === prefs.tz;
const href = buildLink("/week", { ...prefs, tz: key });
return `<a href="${href}" class="tz-link${isCurrent ? " tz-link--active" : ""}"${isCurrent ? ' aria-current="true"' : ""}>${config.label}</a>`;
})
.join(" · ");
const modeLinks = [
{ key: "vcr", label: "VCR" },
{ key: "all", label: "All Shows" },
]
.map(({ key, label }) => {
const isCurrent = key === prefs.mode;
const href = buildLink("/week", { ...prefs, mode: key });
return `<a href="${href}" class="mode-link${isCurrent ? " mode-link--active" : ""}"${isCurrent ? ' aria-current="true"' : ""}>${label}</a>`;
})
.join(" | ");
const themeLinks = [
{ key: "light", label: "☀️ Light" },
{ key: "dark", label: "🌙 Dark" },
{ key: "system", label: "⚙️ System" },
]
.map(({ key, label }) => {
const isCurrent = key === prefs.theme;
const href = buildLink("/week", { ...prefs, theme: key });
return `<a href="${href}" class="theme-link${isCurrent ? " theme-link--active" : ""}"${isCurrent ? ' aria-current="true"' : ""}>${label}</a>`;
})
.join(" · ");
const prevLink = buildLink("/week", { ...prefs, week: prev });
const nextLink = buildLink("/week", { ...prefs, week: next });
return `<!DOCTYPE html>
<html lang="en" data-theme="${prefs.theme}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>${escapeHtml(title)} — VCR Calendar</title>
<style>${css}</style>
</head>
<body>
<header class="site-header">
<h1 class="site-title"><a href="/week">VCR Calendar</a></h1>
<nav class="controls-bar">
<div class="controls-row">${modeLinks}</div>
<div class="controls-row">
<a href="${prevLink}" class="week-nav" aria-label="Previous week">←</a>
<span class="week-label">${weekBounds.label}</span>
<a href="${nextLink}" class="week-nav" aria-label="Next week">→</a>
</div>
<div class="controls-row">${tzLinks}</div>
<div class="controls-row">${themeLinks} · <a href="/week?reset=1" class="reset-link">Reset</a></div>
</nav>
</header>
<main>${bodyContent}</main>
<footer class="site-footer">
<p>voidzero Community Radio</p>
</footer>
</body>
</html>`;
}
function buildLink(path: string, prefs: Record<string, string>): string {
const params = new URLSearchParams();
if (prefs.tz && prefs.tz !== "eastern") params.set("tz", prefs.tz);
if (prefs.theme && prefs.theme !== "system") params.set("theme", prefs.theme);
if (prefs.mode && prefs.mode !== "vcr") params.set("mode", prefs.mode);
if (prefs.week) params.set("week", prefs.week);
const qs = params.toString();
return qs ? `${path}?${qs}` : path;
}
function escapeHtml(s: string): string {
return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
}