#!/usr/bin/env node // Site build for the delivery-arc page (CSP-clean: script-src 'self', no inline JS). // Reads pilot/arc.tpl.html, splits the app "); if (i < 0 || j < i) throw new Error("app script block not found"); let app = tpl.slice(i + 8, j) .replace("__MAN_SURROUND__", man("surround")) .replace("__MAN_NODE__", man("node")) .replace("__MAN_POD__", man("pod")) .replace("__MAN_TRAFFIC__", man("traffic")) .replace("__MAN_ORBIT__", man("orbit")) .replace("__MAN_DOCKER__", man("docker")) .replace("__MAN_CLUSTER__", man("cluster")) .replace("__MAN_GITOPS__", man("gitops")) .replace("__MAN_SUPPLY__", man("supply")) .replace("__MAN_HELM__", man("helm")); let body = tpl.slice(0, i) + tpl.slice(j + 9); const heroes = { __HERO_INTRO__: "intro-establishing.webp", __HERO_SURROUND__: "course-00-surround.webp", __HERO_NODE__: "course-III-node.webp", __HERO_POD__: "course-III-pod.webp", __HERO_TRAFFIC__: "course-IV-traffic.webp", __HERO_ORBIT__: "course-V-orbit.webp", __HERO_DOCKER__: "docker-layers.webp", __HERO_CLUSTER__: "course-II-cluster.webp", __HERO_GITOPS__: "course-VI-gitops.webp", __HERO_SUPPLY__: "course-VII-supply-chain.webp", __HERO_HELM__: "course-VIII-helm-press.webp", __HERO_APPENDIX__: "appendix-dependency-ledger.webp", }; // content-fingerprint everything under /assets/ (immutable-cached by nginx): a fresh // index.html can then never pair with a stale script or image from a previous deploy. mkdirSync(join(DIST, "assets"), { recursive: true }); const fp = buf => createHash("sha256").update(buf).digest("hex").slice(0, 8); const emit = (srcPath, base, ext) => { const buf = readFileSync(srcPath); const name = `${base}.${fp(buf)}.${ext}`; writeFileSync(join(DIST, "assets", name), buf); return { url: "/assets/" + name, buf }; }; const heroUrls = {}; for (const [ph, file] of Object.entries(heroes)) { const base = file.replace(/\.webp$/, ""); const { url, buf } = emit(join(ROOT, "assets/dist", file), base, "webp"); heroUrls[ph] = url; const dims = webpSize(buf); const dimAttr = dims ? ` width="${dims.w}" height="${dims.h}"` : ""; // The intro backdrop is the above-the-fold LCP candidate -> eager. Everything else, // including Course 00's hero, sits below the fold and lazy-loads. const load = ph === "__HERO_INTRO__" ? "eager" : "lazy"; body = body.replace(`src="${ph}"`, `src="${url}"${dimAttr} decoding="async" loading="${load}"`); } { const { url } = emit(join(ROOT, "assets/dist/delivery-flow.svg"), "delivery-flow", "svg"); body = body.replace(`src="__DIAG_FLOW__"`, `src="${url}" width="1180" height="660" decoding="async" loading="lazy"`); } if (body.includes("__HERO_") || body.includes("__DIAG_") || app.includes("__MAN_")) throw new Error("unfilled placeholder"); const favicon = "data:image/svg+xml," + encodeURIComponent( ``); const gsapRef = emit(join(ROOT, "gsap.min.js"), "gsap.min", "js").url; const stRef = emit(join(ROOT, "st.min.js"), "st.min", "js").url; const appName = `arc.${fp(app)}.js`; writeFileSync(join(DIST, "assets", appName), app); const appRef = "/assets/" + appName; const DESC = "Interactive teardown of Kubernetes and OpenShift delivery: containers, Services, GitOps, image supply chains and Helm, explained with scroll-driven exploded diagrams."; const OG_IMG = SITE + heroUrls["__HERO_GITOPS__"]; // shared document shell: every page on the site gets the same head discipline const shell = ({ title, desc, path, ogImg, scripts, bodyHtml }) => ` ${title} ${SKIP_CSS}
${bodyHtml}
${scripts.map(s => ``).join("\n")} `; const html = shell({ title: "The Exploded Cluster", desc: DESC, path: "/cluster", ogImg: OG_IMG, scripts: [gsapRef, stRef, appRef], bodyHtml: body, }); // ---- The Mirror (chapter 02): fingerprint its plates + its app script ------- const MIRROR_DESC = "A pull-through container registry taken apart: why a lab runs its own mirror, the chicken-and-egg loops inside it, and the scars that taught each rule."; let mirror = readFileSync(join(ROOT, "pilot/mirror.tpl.html"), "utf8"); const mirrorPlates = {}; for (const n of ["20", "21", "22", "23", "24", "25"]) { const { url, buf } = emit(join(ROOT, "assets/mirror", `${n}.jpg`), `mirror-${n}`, "jpg"); mirrorPlates[n] = url; const dims = jpegSize(buf); if (!dims) throw new Error(`mirror plate ${n}: JPEG dimensions unreadable`); // plate 20 is the page's first image (near the fold) -> eager/LCP; the rest lazy. const load = n === "20" ? "eager" : "lazy"; mirror = mirror.replace(`__M${n}__`, `${url}" width="${dims.w}" height="${dims.h}" decoding="async" loading="${load}`); } const mirrorJs = readFileSync(join(ROOT, "pilot/mirror.js")); const mirrorJsName = `mirror.${fp(mirrorJs)}.js`; writeFileSync(join(DIST, "assets", mirrorJsName), mirrorJs); mirror = mirror.replace("__MIRROR_JS__", "/assets/" + mirrorJsName); if (mirror.includes("__M")) throw new Error("unfilled mirror placeholder"); const mirrorHtml = shell({ title: "The Mirror", desc: MIRROR_DESC, path: "/mirror", ogImg: SITE + mirrorPlates["20"], scripts: [], bodyHtml: mirror, }); // ---- the directory (index): the chapters of what this place teaches --------- const DIR_DESC = "The Teaching Lab: scroll-driven teardowns of real infrastructure - container platforms, registries and the machinery of delivery, one exploded system per chapter."; let dir = readFileSync(join(ROOT, "pilot/index.tpl.html"), "utf8") .replace("__THUMB_CLUSTER__", heroUrls["__HERO_GITOPS__"]) .replace("__THUMB_MIRROR__", mirrorPlates["20"]); if (dir.includes("__THUMB")) throw new Error("unfilled directory placeholder"); const dirHtml = shell({ title: "The Teaching Lab", desc: DIR_DESC, path: "/", ogImg: SITE + mirrorPlates["20"], scripts: [], bodyHtml: dir, }); writeFileSync(join(DIST, "index.html"), dirHtml); writeFileSync(join(DIST, "cluster.html"), html); writeFileSync(join(DIST, "mirror.html"), mirrorHtml); writeFileSync(join(DIST, "build.json"), JSON.stringify({ revision: BUILD_REV, app: appName, mirror: mirrorJsName }) + "\n"); // --------------------------------------------------------------------------- // Preflight gates: fail the build loudly rather than ship a known defect. // --------------------------------------------------------------------------- const fail = []; const must = (cond, msg) => { if (!cond) fail.push(msg); }; // per-page structural gates (CSP + document hygiene) for every page shipped for (const [pg, doc] of [["cluster", html], ["mirror", mirrorHtml], ["index", dirHtml]]) { must(!(doc.match(/]*src=)[^>]*>/gi) || []).length, `${pg}: inline