// Serving the Volter brand's tokens and faces (company decision 0018) from a page's own base, like // fileResponse (the serve seam's helpers, docs/contributing/architecture.md#the-serve-seam). The files // are written at build by scripts/brand-tokens.ts into the page's gitignored `brand/` directory; this // only reads them and never fetches, so a running world does not reach the brand. import { existsSync } from 'node:fs'; import { join } from 'node:path'; import { fileResponse } from './file-response.ts'; const FONT_TYPES: Record = { woff2: 'font/woff2', woff: 'font/woff', ttf: 'font/ttf', otf: 'font/otf' }; /** Serve `/brand/` from `dir`: `tokens.css` or `fonts/`; 404 for any other name or a file the build did not write. */ export function brandTokensResponse(dir: string, rest: string): Response { const font = /^fonts\/[A-Za-z0-9_.-]+\.(woff2|woff|ttf|otf)$/.exec(rest); if (rest !== 'tokens.css' && !font) return new Response('not found', { status: 404 }); if (!existsSync(join(dir, 'tokens.css'))) return new Response('the brand tokens are not built here; run `bun scripts/brand-tokens.ts`', { status: 404 }); return fileResponse(join(dir, rest), { headers: { 'cache-control': 'no-cache', 'content-type': font ? FONT_TYPES[font[1]!]! : 'text/css; charset=utf-8' } }); }