// Safety net for moving texts into the language files: saves what the prerendered page says // (text, links, labels, meta tags, structured data and the CMS data block, if present) and later // checks that a new build says exactly the same. Styling, scripts, asset hashes and generated class // names are left out, so only a change of wording or content shows up. // // Usage (after `pnpm build`, or `vite build && node scripts/prerender.mjs`): // node scripts/htmlBaseline.mjs save writes .baseline/index.html (ignored by git) // node scripts/htmlBaseline.mjs check compares dist/index.html with .baseline (exit code 1 on a difference) import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; const DIST_FILE = join('dist', 'index.html'); const BASELINE_DIR = '.baseline'; const BASELINE_FILE = join(BASELINE_DIR, 'index.html'); // What stays of the scripts: structured data and data blocks, not code const KEEP_SCRIPT = /type="application\/(?:ld\+json|json)"/; export function normalizeHtml(html) { return ( html .replace(//g, '') .replace(//g, '') .replace(/]*)>([\s\S]*?)<\/script>/g, (all, attrs) => KEEP_SCRIPT.test(attrs) ? all : '', ) .replace(/