diff --git a/src/index.ts b/src/index.ts index 0af2024..a1de559 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,12 +35,12 @@ export default { const slug = showMatch[1]; const show = shows.find((s) => s.slug === slug); if (!show) { - return new Response(renderNotFound(), { status: 404, headers: { "Content-Type": "text/html; charset=utf-8" } }); + return new Response(renderNotFound(prefs), { status: 404, headers: { "Content-Type": "text/html; charset=utf-8" } }); } const html = renderShowDetail(show, prefs); return new Response(html, { headers }); } - return new Response(renderNotFound(), { status: 404, headers: { "Content-Type": "text/html; charset=utf-8" } }); + return new Response(renderNotFound(prefs), { status: 404, headers: { "Content-Type": "text/html; charset=utf-8" } }); }, } satisfies ExportedHandler; diff --git a/src/render/not-found.ts b/src/render/not-found.ts index ac4c538..8655c63 100644 --- a/src/render/not-found.ts +++ b/src/render/not-found.ts @@ -1,3 +1,8 @@ -export function renderNotFound(): string { - return "
Not found.
"; +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 = ``; + return renderPage("Not Found", body, defaultPrefs); } diff --git a/src/render/show-detail.test.ts b/src/render/show-detail.test.ts new file mode 100644 index 0000000..c693f3e --- /dev/null +++ b/src/render/show-detail.test.ts @@ -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); + }); +}); diff --git a/src/render/show-detail.ts b/src/render/show-detail.ts index 0d470e2..c8ec49b 100644 --- a/src/render/show-detail.ts +++ b/src/render/show-detail.ts @@ -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 "show"; + +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 = `${dayLabel}, ${startDisplay} – ${endDisplay}
`; + + if (show.hosts.length > 0) { + const hosts = show.hosts.map((h) => escapeHtml(h)).join(", "); + html += `${hosts}
`; + } + + html += `${escapeHtml(show.shortDescription)}
`; + + const links: string[] = []; + if (show.websiteUrl.trim() !== "") { + links.push(`Website`); + } + if (show.feedUrl.trim() !== "") { + links.push(`Feed`); + } + if (links.length > 0) { + html += `