/** * What the public site shows right now: Coming soon until the first publish (ยง5, decision 3), then * the latest published version. After the first publish there's no going back to Coming soon. */ import { WEBSITE_TEMPLATES, type WebsiteTemplate } from '@crosscode/contracts'; import type { Ctx } from '../context.js'; export type SiteStatus = | { mode: 'coming-soon' } | { mode: 'published'; version: number; publishedAt: string; template: WebsiteTemplate | null }; export async function siteStatus(ctx: Ctx): Promise { const latest = await ctx.db.siteVersion.findFirst({ orderBy: { number: 'desc' }, select: { number: true, publishedAt: true, snapshot: true } }); if (!latest) return { mode: 'coming-soon' }; const t = (latest.snapshot as { design?: { template?: unknown } } | null)?.design?.template; const template = (WEBSITE_TEMPLATES as readonly unknown[]).includes(t) ? (t as WebsiteTemplate) : null; return { mode: 'published', version: latest.number, publishedAt: latest.publishedAt.toISOString(), template }; }