/** Server-rendered pages. The event list and forms are drawn by public/app.js from the boot JSON; home and create by public/home.js. */ import { HERO_SVG } from './art.ts' import { THEMES } from './pies.ts' const DESCRIPTION_FALLBACK = "Let us know what pie you're bringing and see what everyone else is bringing." function escapeHtml(value: string) { return value.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''') } function bootJson(value: unknown) { return JSON.stringify(value).replace(/ } type PublicEvent = { slug: string; code: string; title: string; date: string; time: string; place: string; blurb: string; theme: string; version: number; when: { day: string; time: string; short: string; medium: string } } function head(input: Shared & { title: string; desc: string; ogTitle?: string; ogUrl: string; ogImage: string; ogAlt: string; manifest: string }) { const assets = escapeHtml(input.assetBase) const v = encodeURIComponent(input.assetVersion) return ` ${escapeHtml(input.title)} ` } /** Update banner, install button and toast shared by every page (driven by the scripts). */ function chrome() { return ` ` } function script(input: Shared, name: string) { return `` } export function eventPageHtml(input: Shared & { event: PublicEvent pies: unknown[] mode: 'guest' | 'admin' | 'not-admin' | 'sign-in' visitor: { username: string } | null isHost: boolean loginUrl: string pushKey: string }) { const { event } = input const eventPath = `${input.appBase}/e/${event.slug}` const where = event.place ? ` ${event.place}.` : '' const desc = `${event.when.day} at ${event.when.time}.${where} ${DESCRIPTION_FALLBACK}` const ogImage = `${input.site}/e/${event.slug}/og.png?v=${event.version}` const theme = event.theme in THEMES ? event.theme : 'harvest' return ` ${head({ ...input, title: `${event.title} 🥧 ${event.when.day}`, ogTitle: `${event.title} 🥧 ${event.when.medium} · ${event.when.time}`, desc, ogUrl: `${input.site}/e/${event.slug}`, ogImage, ogAlt: `A pumpkin pie with whipped cream beside the words ${event.title}, ${event.when.medium}, ${event.when.time}${event.place ? `, ${event.place}` : ''}`, manifest: `${eventPath}/manifest.webmanifest` })}

You're invited to

${escapeHtml(event.title)}

📅 ${escapeHtml(event.when.day)} ⏰ ${escapeHtml(event.when.time)} 🏡 ${escapeHtml(event.place)}

${escapeHtml(event.blurb)}

I'm bringing pie!

Pies on the way

Change this pie

${chrome()} ${script(input, 'pwa.js')} ${script(input, 'app.js')} ` } function simplePage(input: Shared & { title: string; desc: string; body: string; boot: unknown; ogUrl: string; scriptName?: string }) { return ` ${head({ ...input, ogUrl: input.ogUrl, ogImage: `${publicAssetUrl(input.site, input.appBase, input.assetBase)}/og.png?v=${encodeURIComponent(input.assetVersion)}`, ogAlt: 'A pumpkin pie with whipped cream beside the words Pie Night', manifest: `${input.appBase}/manifest.webmanifest` })}

Pie Night

${input.body}
${chrome()} ${script(input, 'pwa.js')} ${script(input, 'home.js')} ` } export function homePageHtml(input: Shared & { visitor: { username: string } | null; mine: PublicEvent[]; loginUrl: string }) { const mine = input.mine.length ? `

Your pie nights

` : '' const body = `

Gather your people for pie. Everyone says what they are bringing, sees what is coming, and nobody needs an account.

Got a pie night code?

Hosting?

Start a pie night in a minute. You sign in with Kody so you can change the details later; your guests never need to.

Start a pie night 🥧
${mine}` return simplePage({ ...input, title: 'Pie Night', desc: 'Plan a pie night: guests say what pie they are bringing and see everyone else’s.', body, ogUrl: `${input.site}/`, boot: { appBase: input.appBase, page: 'home' } }) } export function newEventPageHtml(input: Shared & { visitor: { username: string } | null; loginUrl: string }) { const themes = Object.entries(THEMES) .map(([k, t], i) => ``) .join('') const body = input.visitor ? `

Start a pie night 🥧

Theme${themes}

Signed in as ${escapeHtml(input.visitor.username)}. You will be the host.

` : `

Hosts sign in first 🔑

Sign in with Kody to start a pie night. You need it to change the details later. Guests never sign in.

Sign in with Kody
` return simplePage({ ...input, title: 'Start a pie night', desc: 'Plan a pie night: guests say what pie they are bringing and see everyone else’s.', body, ogUrl: `${input.site}/new`, boot: { appBase: input.appBase, page: 'new' } }) } export function notFoundHtml(input: Shared & { code: string }) { const body = `

No pie night here 🥧

${input.code ? `We could not find a pie night with the code ${escapeHtml(input.code)}.` : 'That page is not on the menu.'} Double-check the link, or try the code again.

` return simplePage({ ...input, title: 'Pie night not found', desc: 'Pie Night', body, ogUrl: `${input.site}/`, boot: { appBase: input.appBase, page: 'missing' } }) } export function offlineHtml(input: Shared) { const body = `

You're offline 🥧

This pie night page has not been saved on this device yet. Connect to the internet and try again. Pages you have opened before still work offline.

` return simplePage({ ...input, title: 'Offline', desc: 'Pie Night', body, ogUrl: `${input.site}/`, boot: { appBase: input.appBase, page: 'offline' } }) } function publicAssetUrl(site: string, appBase: string, assetBase: string) { if (/^https?:\/\//.test(assetBase)) return assetBase const origin = appBase && site.endsWith(appBase) ? site.slice(0, site.length - appBase.length) : site return origin + assetBase }