feat: week page composition, show detail pages, and styled 404

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-02 18:40:35 -05:00
parent 7b484e5664
commit d96f83c0a6
5 changed files with 187 additions and 8 deletions

View File

@@ -1,3 +1,8 @@
export function renderNotFound(): string {
return "<!DOCTYPE html><html><body><h1>404</h1><p>Not found.</p></body></html>";
import { renderPage } from "./page";
import type { Preferences } from "../types";
export function renderNotFound(prefs?: Preferences): string {
const defaultPrefs: Preferences = prefs ?? { tz: "eastern", theme: "system", mode: "vcr", week: "", setCookies: [] };
const body = `<div class="not-found"><h2>404 — Not Found</h2><p>That page doesn't exist.</p><p><a href="/week">← Back to calendar</a></p></div>`;
return renderPage("Not Found", body, defaultPrefs);
}

View File

@@ -0,0 +1,78 @@
import { describe, it, expect } from "vitest";
import { renderShowDetail } from "./show-detail";
import type { Show, Preferences } from "../types";
const babShow: Show = {
slug: "bowl-after-bowl",
name: "Bowl After Bowl",
shortDescription: "The flagship Small Group talk show.",
websiteUrl: "https://bowlafterbowl.com",
feedUrl: "https://feed.bowlafterbowl.com/feed.xml",
accentColor: "#f2b705",
hosts: ["Spencer", "DuhLaurien"],
isSmallGroup: true,
isVcr: true,
isActive: true,
schedule: { day: "tuesday", startTime: "22:00", endTime: "01:00+1", timezone: "America/New_York", recurrence: "weekly" },
};
const defaultPrefs: Preferences = { tz: "eastern", theme: "system", mode: "vcr", week: "2026-W45", setCookies: [] };
describe("renderShowDetail", () => {
it("includes the show name as heading", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("Bowl After Bowl");
});
it("includes the schedule line", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("Tuesday");
expect(html).toMatch(/10:00\s*PM/i);
});
it("includes host names", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("Spencer");
expect(html).toContain("DuhLaurien");
});
it("includes short description", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("flagship Small Group talk show");
});
it("includes website link", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("https://bowlafterbowl.com");
});
it("includes feed link when available", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("feed.bowlafterbowl.com");
});
it("shows VCR badge", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("VCR");
});
it("shows Small Group badge", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("Small Group");
});
it("includes back to calendar link", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("Back to calendar");
});
it("applies accent color", () => {
const html = renderShowDetail(babShow, defaultPrefs);
expect(html).toContain("#f2b705");
});
it("converts times to the selected timezone", () => {
const html = renderShowDetail(babShow, { ...defaultPrefs, tz: "central" });
expect(html).toMatch(/9:00\s*PM/i);
});
});

View File

@@ -1,4 +1,92 @@
import { renderPage } from "./page";
import { TIMEZONE_CONFIG, convertTime } from "../time/zones";
import { getWeekBounds } from "../time/week";
import type { Show, Preferences } from "../types";
export function renderShowDetail(_show: Show, _prefs: Preferences): string {
return "<!DOCTYPE html><html><body>show</body></html>";
const DAY_ORDER = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] as const;
const DAY_LABELS = ["Sundays", "Mondays", "Tuesdays", "Wednesdays", "Thursdays", "Fridays", "Saturdays"];
export function renderShowDetail(show: Show, prefs: Preferences): string {
const targetZone = TIMEZONE_CONFIG[prefs.tz].iana;
const weekBounds = getWeekBounds(prefs.week, prefs.tz);
const sourceDayIdx = DAY_ORDER.indexOf(show.schedule.day);
const refDate = new Date(weekBounds.start);
refDate.setUTCDate(refDate.getUTCDate() + sourceDayIdx);
const [startH, startM] = parseHourMinute(show.schedule.startTime);
const convertedStart = convertTime(startH, startM, show.schedule.timezone, targetZone, refDate);
const isOvernightSource = show.schedule.endTime.includes("+1");
const endRaw = show.schedule.endTime.replace("+1", "");
const [endH, endM] = parseHourMinute(endRaw);
const endRef = new Date(refDate);
if (isOvernightSource) {
endRef.setUTCDate(endRef.getUTCDate() + 1);
}
const convertedEnd = convertTime(endH, endM, show.schedule.timezone, targetZone, endRef);
const displayDayIdx = (sourceDayIdx + convertedStart.dayOffset + 7) % 7;
const dayLabel = DAY_LABELS[displayDayIdx];
const startDisplay = formatTime12(convertedStart.hour, convertedStart.minute);
const endDisplay = formatTime12(convertedEnd.hour, convertedEnd.minute);
const backHref = `/week?week=${encodeURIComponent(prefs.week)}&tz=${encodeURIComponent(prefs.tz)}`;
let html = `<div class="show-detail" style="--show-accent:${escapeHtml(show.accentColor)}">`;
html += `<h1 class="show-detail__heading">${escapeHtml(show.name)}</h1>`;
html += `<p class="show-detail__schedule">${dayLabel}, ${startDisplay} – ${endDisplay}</p>`;
if (show.hosts.length > 0) {
const hosts = show.hosts.map((h) => escapeHtml(h)).join(", ");
html += `<p class="show-detail__hosts">${hosts}</p>`;
}
html += `<p class="show-detail__description">${escapeHtml(show.shortDescription)}</p>`;
const links: string[] = [];
if (show.websiteUrl.trim() !== "") {
links.push(`<a href="${escapeHtml(show.websiteUrl)}">Website</a>`);
}
if (show.feedUrl.trim() !== "") {
links.push(`<a href="${escapeHtml(show.feedUrl)}">Feed</a>`);
}
if (links.length > 0) {
html += `<div class="show-detail__links">${links.join("")}</div>`;
}
const badges: string[] = [];
if (show.isVcr) {
badges.push('<span class="show-detail__badge">VCR</span>');
}
if (show.isSmallGroup) {
badges.push('<span class="show-detail__badge">Small Group</span>');
}
if (show.schedule.recurrence === "biweekly") {
badges.push('<span class="show-detail__badge">Bi-weekly</span>');
}
if (badges.length > 0) {
html += `<div class="show-detail__badges">${badges.join("")}</div>`;
}
html += `<p class="show-detail__back"><a href="${backHref}">\u2190 Back to calendar</a></p>`;
html += "</div>";
return renderPage(show.name, html, prefs);
}
function parseHourMinute(time: string): [number, number] {
const clean = time.replace("+1", "");
const [h, m] = clean.split(":").map(Number);
return [h, m];
}
function formatTime12(hour: number, minute: number): string {
const period = hour < 12 ? "AM" : "PM";
const h = hour % 12 || 12;
return `${h}:${String(minute).padStart(2, "0")} ${period}`;
}
function escapeHtml(s: string): string {
return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
}

View File

@@ -1,4 +1,12 @@
import { renderPage } from "./page";
import { renderWeekGrid } from "./week-grid";
import { renderAgenda } from "./agenda";
import type { Show, Preferences } from "../types";
export function renderWeekPage(_shows: Show[], _prefs: Preferences): string {
return "<!DOCTYPE html><html><body>week</body></html>";
export function renderWeekPage(shows: Show[], prefs: Preferences): string {
const grid = renderWeekGrid(shows, prefs);
const agenda = renderAgenda(shows, prefs);
const bodyContent = grid + agenda;
const modeLabel = prefs.mode === "vcr" ? "VCR Schedule" : "All Shows Schedule";
return renderPage(modeLabel, bodyContent, prefs);
}