→ 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}}`
}),
)
}
// House style for everything we write (slides, notes, data, docs): no em or en dashes, ASCII quotes only, and
// never the word "moat". Vendored code is not checked.
{
const files = [
...readdirSync(join(src, 'slides')).filter((f) => f.endsWith('.html')).map((f) => join(src, 'slides', f)),
...readdirSync(join(root, 'data')).filter((f) => f.endsWith('.json')).map((f) => join(root, 'data', f)),
...['README.md', 'AGENTS.md', 'LAB-GUIDE.md'].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(/[\u2013\u2014\u2018\u2019\u201C\u201D]|\bmoats?\b/i)
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, no "moat"):\n${bad.join('\n')}`)
}
const rungs = JSON.parse(readFileSync(join(root, 'data/rungs.json'), 'utf8'))
const factory = JSON.parse(readFileSync(join(root, 'data/factory.json'), 'utf8'))
// Hour slide-set and event overrides, read by deck.js. Inlined as JSON, so nothing
// renders unless deck.js applies them. Each event with a podiumUrl gets a QR data URI
// generated here (no external QR service).
const hour = JSON.parse(readFileSync(join(root, 'data/hour.json'), 'utf8'))
const events = JSON.parse(readFileSync(join(root, 'data/events.json'), 'utf8')).events
for (const [slug, ev] of Object.entries(events)) {
if (!ev.podiumUrl) throw new Error(`event ${slug}: missing podiumUrl`)
if (!ev.title || !ev.format || !ev.displayUrl || !ev.pageTitle) throw new Error(`event ${slug}: missing title, format, displayUrl or pageTitle`)
const svg = await QRCode.toString(ev.podiumUrl, {
type: 'svg',
errorCorrectionLevel: 'H',
margin: 1,
width: 256,
color: { dark: '#111417', light: '#FFFFFF' },
})
ev.qrDataUri = `data:image/svg+xml;base64,${Buffer.from(svg).toString('base64')}`
}
const SCORES = ['done', 'partial', 'missing', 'unknown', 'n/a']
const all = rungs.groups.flatMap((g) => g.rungs)
for (const r of all) if (r.score !== null && !SCORES.includes(r.score)) throw new Error(`rung ${r.n}: bad score ${r.score}`)
const counts = SCORES.map((s) => [s, all.filter((r) => r.score === s).length])
// Ladder slide: rung names only, grouped by pillar. The "done when" wording and the
// scores go into the speaker notes ({{RUNGS_NOTES}}).
const group = (g) => `${esc(g.id)} · ${esc(g.label)}
${g.rungs
.map((r) => `
${r.n}${esc(r.title)}
`)
.join('')}
`
const byId = Object.fromEntries(rungs.groups.map((g) => [g.id, g]))
const rungsHtml = `
${group(byId.P1)}
${group(byId.P2)}${group(byId.P3)}
${group(byId.KI)}
`
const rungsNotes = `Done when (autopilot skill ${esc(rungs.skillVersion)}):
${all
.map((r) => `- ${r.n}. ${esc(r.title)}: ${code(r.doneWhen)}${rungs.showScores ? ` (mediarss: ${r.score === null ? 'not scored; the dry run predates this rung' : esc(r.score)})` : ''}
`)
.join('')}
`
// Factory slide: the numbers on screen, their GitHub queries in the speaker notes.
const factoryHtml = `${factory.stats
.map((s) => `
${esc(s.value)}
${esc(s.label)}
`)
.join('')}
`
const factoryNotes = `Sources (${esc(factory.asOf)}), GitHub search:
${factory.stats
.map((s) => `- ${esc(s.value)} ${esc(s.label)}:
${esc(s.query)} `)
.join('')}
`
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}`)
labels.add(label)
html = html.replace(/`)
return html
.replace('{{RUNGS}}', () => rungsHtml)
.replace('{{RUNGS_NOTES}}', () => rungsNotes)
.replace('{{FACTORY}}', () => factoryHtml)
.replace('{{FACTORY_NOTES}}', () => factoryNotes)
}).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)
.replace('', () => ``)
.replace('', () => ``)
page = page
.replace(/url\('fonts\/([\w.-]+)'\)/g, (_, f) => `url('${dataUri('fonts/' + f)}')`)
.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(/