// Builds the Reveal.js deck from src/deck.html + src/slides/*.html (file-name order). Reveal.js and
// its notes plugin come from the pinned npm package and are inlined with the CSS and JS. Writes
// dist/index.html (fully self-contained, fonts and images inlined: opens from disk with no network)
// and app/assets.generated.ts (the hosted page plus content-hashed asset files, served by the app).
import { readdirSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs'
import { join, extname } from 'node:path'
import { createHash } from 'node:crypto'
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 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.
function scopeCss(css, sel) {
// Drop comments first: commas inside a comment would otherwise split into bogus selectors.
css = css.replace(/\/\*[\s\S]*?\*\//g, '')
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.includes(':scope') ? s.replace(':scope', sel) : `${sel} ${s}`,
)
return `\n${out.join(', ')} {${decls}}`
}),
)
}
// House style for everything we write: no em or en dashes and ASCII quotes only.
{
const files = [
...readdirSync(join(src, 'slides')).filter((f) => f.endsWith('.html')).map((f) => join(src, 'slides', f)),
...['README.md', 'AGENTS.md', 'BEATS.md', 'src/deck.html', 'src/c/deck.css', 'src/c/deck.js', 'src/sw.js'].map((f) => join(root, f)),
]
const bad = []
for (const file of files) {
let text
try { text = readFileSync(file, 'utf8') } catch { continue }
text.split('\n').forEach((line, i) => {
const m = line.match(/[–—‘’“”]/)
if (m) bad.push(`${file.slice(root.length)}:${i + 1}: ${JSON.stringify(m[0])}`)
})
}
if (bad.length) throw new Error(`house style (no em/en dashes, ASCII quotes):\n${bad.join('\n')}`)
}
// Brand marks and Kody Iconic glyphs, inlined so they follow the theme via currentColor.
const snippets = {
KODY_MARK: readFileSync(join(src, 'c/kody-mark.svg.html'), 'utf8').trim(),
EPE_MARK: readFileSync(join(src, 'c/epe-mark.svg.html'), 'utf8').trim(),
...JSON.parse(readFileSync(join(src, 'c/icons.json'), 'utf8')),
}
// Each inlined copy of an SVG with internal ids (the EpicProduct.engineer gradient) gets its own
// ids: a url(#id) that points at a copy inside a hidden slide would render nothing.
let snippetCopy = 0
const fill = (html) => html.replace(/\{\{([A-Z_]+)\}\}/g, (m, k) => {
if (!(k in snippets)) throw new Error(`unknown snippet ${m}`)
const n = ++snippetCopy
return snippets[k].replace(/id="([\w-]+)"/g, (_, id) => `id="${id}-${n}"`).replace(/url\(#([\w-]+)\)/g, (_, id) => `url(#${id}-${n})`)
})
const slideFiles = readdirSync(join(src, 'slides')).filter((f) => f.endsWith('.html')).sort()
const labels = new Set()
const slidesHtml = slideFiles.map((f) => {
let html = readFileSync(join(src, 'slides', f), 'utf8').trim()
const label = html.match(/^`)
if (labels.has(label)) throw new Error(`${f}: duplicate label ${label}`)
if (!/