/** * BLANKS: words only the owner can give (the legal name, the postal address, * a date, how long something is kept, a store link) are written in a page as * `[[blank: what is missing]]`, in text or as a link's href. * * A live build (`pnpm build:live`, which `wrangler deploy` runs first, see * wrangler.jsonc `build`; src/site/build.ts) refuses to finish * while any page holds one, and names every blank on every page, so nothing * with a blank can go live by accident. A preview build (`pnpm build`, which * CI's `turbo build` and `wrangler dev` run) lets them through and shows each * one marked on the page. */ export const BLANK = /\[\[blank: ([^\]]+)\]\]/g; /** Every blank in a page, in order, by its words. */ export function blanksIn(html: string): string[] { return [...html.matchAll(BLANK)].map((m) => m[1]!.trim()); } /** Each page's blanks, keyed by its file, leaving out the pages with none. */ export function blanksOf(pages: Record): Record { return Object.fromEntries( Object.entries(pages) .map(([name, html]) => [name, blanksIn(html)] as const) .filter(([, found]) => found.length > 0), ); } /** The refusal a production build stops with: every blank, page by page. */ export function refusal(found: Record): string { const lines = Object.entries(found).flatMap(([name, list]) => [` ${name}`, ...list.map((b) => ` - ${b}`)]); return [ "The site still has blanks only the owner can fill, so it will not build for production:", ...lines, "Fill each one in the page, or build a preview with `pnpm build`.", ].join("\n"); } const escape = (s: string) => s.replace(/&/g, "&").replace(/"/g, """).replace(/ `href="#blank" class="blank" title="Blank: ${escape(what.trim())}"`) .replace(BLANK, (_, what: string) => `[${escape(what.trim())}]`); } /** * PREVIEW ONLY: text written `…` is shown by a preview build and left out of a * live one, for words the owner reads on the preview before they are public (Comms' help, 25 Nov 2026). */ export const forPreview = (html: string, preview: boolean): string => preview ? html.replace(/\n?/g, "") : html.replace(/[\s\S]*?\n?/g, "");