// The deck's rules. Fails when a slide breaks one, and writes metrics.json for the review pack. // The limits are the project's own: change them with a contribution, like anything else. import { existsSync, readFileSync, writeFileSync } from "node:fs"; import { countWords, parseDeck } from "./deck-lib.mjs"; const RULES = { minSlides: 4, maxSlides: 12, maxWords: 40, maxTitleWords: 10 }; const slides = parseDeck(readFileSync("deck.md", "utf8")); const problems = []; if (slides.length < RULES.minSlides || slides.length > RULES.maxSlides) problems.push(`the deck has ${slides.length} slides; keep it between ${RULES.minSlides} and ${RULES.maxSlides}`); for (const s of slides) { const where = `slide ${s.n} ("${s.title || "untitled"}")`; if (!s.title) problems.push(`${where} has no "# Title" line`); if (countWords(s.title) > RULES.maxTitleWords) problems.push(`${where}: the title has more than ${RULES.maxTitleWords} words`); const words = countWords(s.content); if (words > RULES.maxWords) problems.push(`${where} has ${words} words; the most is ${RULES.maxWords}`); if (/\b(TODO|TK|lorem ipsum)\b/i.test(`${s.title}\n${s.content}`)) problems.push(`${where} has a placeholder (TODO, TK or lorem ipsum)`); for (const m of s.content.matchAll(/!\[[^\]]*\]\(([^)\s]+)\)/g)) if (!/^https?:/.test(m[1]) && !existsSync(m[1])) problems.push(`${where} shows ${m[1]}, which isn't in the repo`); } const words = slides.map((s) => countWords(s.content)); writeFileSync( "metrics.json", JSON.stringify( { slides: { value: slides.length }, words: { value: words.reduce((a, b) => a + b, 0), better: "lower" }, most_words_on_a_slide: { value: Math.max(0, ...words), better: "lower" }, slides_with_notes: { value: slides.filter((s) => s.notes).length, better: "higher" }, }, null, 2, ) + "\n", ); if (problems.length) { console.error(problems.map((p) => `✗ ${p}`).join("\n")); process.exit(1); } console.log(`✓ ${slides.length} slides pass the deck rules`);