import { readFile } from 'node:fs/promises'; import path from 'node:path'; import type { Font } from 'satori'; import { SANS, SERIF } from './layout'; /** * Font binaries for the panel renderer, read from `public/fonts` rather than * from `node_modules`. * * The rendered pixels feed a content hash that decides whether the e-ink panel * redraws, so they have to be reproducible. Vendored files make that true; an * install tree or a CDN would not. */ const FILES: { file: string; name: string; weight: Font['weight'] }[] = [ { file: 'inter-400.woff', name: SANS, weight: 400 }, { file: 'inter-600.woff', name: SANS, weight: 600 }, { file: 'inter-700.woff', name: SANS, weight: 700 }, { file: 'source-serif-600.woff', name: SERIF, weight: 600 }, ]; let cached: Font[] | null = null; export async function loadScreenFonts(): Promise { if (cached) { return cached; } const directory = path.join(process.cwd(), 'public', 'fonts'); cached = await Promise.all( FILES.map(async ({ file, name, weight }) => ({ name, data: await readFile(path.join(directory, file)), weight, style: 'normal' as const, })), ); return cached; }