// Post-build: give build/play.html its own social/canonical metadata. // // The app is a static SPA (ssr=false), so every prerendered shell ships app.html's // HOMEPAGE — meaning a shared /play link previews as the news homepage. Client // svelte:head can't fix that for non-JS social scrapers (Twitter/Slack/iMessage/etc.). // So we rewrite the static head of play.html here, at build time. Deep-linked variants // (/play?game=…) are served the same file, so they inherit this games-hub preview. import { readFile, writeFile } from 'node:fs/promises'; const FILE = new URL('../build/play.html', import.meta.url); const URL_PLAY = 'https://upbeatbytes.com/play'; const TITLE = 'Play · Upbeat Bytes — calm daily games'; const DESC = 'A calm set of daily games — Daily Word, Word Search, Bloom, and Memory Match. ' + 'A friendly little break from the doomscroll.'; const subs = [ [/[\s\S]*?<\/title>/, `<title>${TITLE}`], [//, ``], [//, ``], [//, ``], [//, ``], [//, ``], [//, ``], [//, ``], ]; let html = await readFile(FILE, 'utf8'); const missed = []; for (const [re, repl] of subs) { if (!re.test(html)) { missed.push(re.source.slice(0, 40)); continue; } html = html.replace(re, repl); } // Fail loudly if the homepage head drifted — better a broken build than silently // shipping the wrong /play preview again. if (missed.length) { console.error('patch-play-head: these head tags were not found (app.html changed?):\n ' + missed.join('\n ')); process.exit(1); } await writeFile(FILE, html); console.log('patch-play-head: rewrote build/play.html head → /play metadata');