/* 校验目录页 PAGES 的每条路由都指向真实存在的文件,并统计各阶段上线情况 */ const fs = require("fs"), path = require("path"); const SITE = "SRE工程师/sre-learning-path"; const html = fs.readFileSync(path.join(SITE, "index.html"), "utf8"); const block = html.match(/const PAGES = \{([\s\S]*?)\};/)[1]; const pairs = [...block.matchAll(/"([^"]+)":\s*"([^"]+)"/g)]; let bad = 0; for (const [, k, v] of pairs) { if (!fs.existsSync(path.join(SITE, v))) { console.log("✗ 死路由", k, "->", v); bad++; } } console.log(`PAGES 条目 ${pairs.length} 条,死路由 ${bad} 条`); /* 按阶段统计:目录页模块数 vs 已登记路由数 */ const stages = [...html.matchAll(/id:"(s\d)"[\s\S]*?modules:\[([\s\S]*?)\n \]/g)]; for (const [, id, body] of stages) { const mods = (body.match(/\n t:"/g) || []).length; const reg = pairs.filter(m => m[1].startsWith(id + "-")).length; console.log(` 阶段 ${id.slice(1)}:模块 ${mods},已登记详解 ${reg}${reg === mods ? " ✓ 全部上线" : " ← 筹备中"}`); } process.exitCode = bad ? 1 : 0;