// Builds one fully self-contained Reveal.js page from src/deck.html + src/slides/*.html // (file-name order), grouped into Reveal vertical stacks by src/slides/groups.json. Reveal.js and its notes plugin come from the pinned npm package // (node_modules/reveal.js) and are inlined with the fonts, images, CSS and JS. // Writes dist/index.html (the offline build) and app/assets.generated.ts (served by the app). // Fails on an em dash (U+2014) anywhere in the source or the output, and on banned words in // slide text and notes. import { readdirSync, readFileSync, writeFileSync, mkdirSync, statSync } from 'node:fs' import { join, extname, relative } from 'node:path' const root = new URL('..', import.meta.url).pathname const src = join(root, 'src') const types = { '.png': 'image/png', '.svg': 'image/svg+xml', '.woff2': 'font/woff2', '.ico': 'image/x-icon', '.webp': 'image/webp', '.jpg': 'image/jpeg' } const EM_DASH = '\u2014' // Every text file we own: src/, scripts/, app/router.ts, docs, package.json. const walk = (dir) => readdirSync(dir).flatMap((name) => { const p = join(dir, name) return statSync(p).isDirectory() ? walk(p) : [p] }) const textExt = new Set(['.html', '.css', '.js', '.mjs', '.ts', '.json', '.md', '.svg']) const owned = [...walk(src), ...walk(join(root, 'scripts')), join(root, 'app/router.ts'), join(root, 'README.md'), join(root, 'AGENTS.md'), join(root, 'package.json')] const dashHits = owned .filter((f) => textExt.has(extname(f))) .flatMap((f) => readFileSync(f, 'utf8').split('\n').flatMap((line, i) => (line.includes(EM_DASH) ? [`${relative(root, f)}:${i + 1}`] : []))) if (dashHits.length) throw new Error(`em dash (U+2014) found, use a comma, colon or period instead:\n${dashHits.join('\n')}`) // c/ → data: URI, so the page never requests anything. const dataUri = (rel) => { const file = join(src, 'c', rel) const type = types[extname(file)] if (!type) throw new Error(`No content type for ${rel}`) return `data:${type};base64,${readFileSync(file).toString('base64')}` } // Rewrites `@scope { a, b { ... } }` into rules prefixed with the slide's selector, // so slide CSS stays isolated in browsers without @scope support. function scopeCss(css, sel) { return css.replace(/@scope\s*\{([\s\S]*)\}\s*$/m, (_, body) => body.replace(/([^{}]+)\{([^{}]*)\}/g, (_, selectors, decls) => { const out = selectors.split(',').map((s) => s.trim()).filter(Boolean).map((s) => s.startsWith(':scope') ? sel + s.slice(6) : `${sel} ${s}`, ) return `\n${out.join(', ')} {${decls}}` }), ) } // Slide text rules: present tense, no "used to / now / switched / removed / we moved". const banned = /\b(used to|now|switched|removed|we moved)\b/i const visibleText = (html) => html.replace(/`)) } // Vertical stacks: each group becomes an outer
holding its slides, like the source deck. // Every slide is in exactly one group, and the groups read in file-name order, so the linear // order (Space / N, slide numbers) matches the files. const { groups } = JSON.parse(readFileSync(join(src, 'slides/groups.json'), 'utf8')) const grouped = groups.flat() const fileOrder = [...labels] if (grouped.length !== new Set(grouped).size) throw new Error('groups.json lists a slide twice') for (const id of fileOrder) if (!grouped.includes(id)) throw new Error(`groups.json is missing slide ${id}`) for (const id of grouped) if (!labels.has(id)) throw new Error(`groups.json names unknown slide ${id}`) if (grouped.join() !== fileOrder.join()) throw new Error('groups.json order must match src/slides file-name order') const slidesHtml = groups.map((ids) => `
\n${ids.map((id) => slideById.get(id)).join('\n')}\n
`).join('\n') if (wordProblems.length) throw new Error(`banned words in slide text or notes (keep it present tense):\n${wordProblems.join('\n')}`) // `vendor:` reads from node_modules (pinned in package.json); other names from src/c/. const readAsset = (f) => (f.startsWith('vendor:') ? readFileSync(join(root, 'node_modules', f.slice(7)), 'utf8') : readFileSync(join(src, 'c', f), 'utf8')) // Inlined JS must not close the `) .replace('', () => slidesHtml) page = page .replace(/url\('fonts\/([\w.-]+)'\)/g, (_, f) => `url('${dataUri('fonts/' + f)}')`) .replace(/url\((['"]?)c\/([\w./-]+)\1\)/g, (_, q, p) => `url('${dataUri(p)}')`) .replace(/(src|href)="c\/([\w./-]+)"/g, (_, attr, p) => `${attr}="${dataUri(p)}"`) // Check the markup and CSS (inline scripts are vendored code; the verify step blocks network anyway). // Plain https links on are navigation the presenter clicks, not resources the page loads. const markup = page.replace(/