init: SRE 学习路径站点(阶段 0-3 详解)与项目资料
站点 - knowledge/sre-learning-path/:离线静态站,无外部依赖、无需构建 - 目录页 index.html 按 7 个阶段组织,阶段 0-3 共 15 个模块已上线详解 - 阶段 0 Linux/网络/编程 3 模块、阶段 1 Nginx/部署/容器/CI-CD 4 模块 - 阶段 2 指标/日志/链路/看板 4 模块、阶段 3 SLO/高可用/容量/混沌 4 模块 - 共 203 个页面(105 章 / 317 小节),每章含场景推演与可复制实操 结构 - 模块目录 modules/<dir>/index.html + NN-<slug>.html 章节页 - 共享资源 assets/doc.css、doc.js(目录滚动高亮、代码块增强、主题切换) - 静态侧边导航由 tools/build-nav.js 生成,tools/check-pages.js 全站校验 内容生成器 .sre-s23/(站点外,供阶段 4-6 复用) - SPEC.md 撰写规范、README.md 流程说明 - gen.js 由 content/*.js 生成页面骨架,保证各模块样式一致 - check-pre.js / verify-template.js / fix-esc.js / coverage.js 校验工具 其它 - project/:AI Agent 面试题库、场景题集 - 增加 .gitattributes 统一 LF 行尾,忽略沙箱诊断产物
This commit is contained in:
55
.sre-s23/verify-template.js
Normal file
55
.sre-s23/verify-template.js
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env node
|
||||
/* ==========================================================================
|
||||
样式一致性核对
|
||||
① 以阶段 0 / 1 的既有页面为基线,收集它们用到的全部 class;
|
||||
② 扫描新模块页面,报告任何「基线里没有、doc.css 里也没有」的 class。
|
||||
这能证明新页面的样式与既有页面完全同源,而不是自创了一套。
|
||||
node .sre-s23/verify-template.js <模块目录名...>
|
||||
========================================================================== */
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const SITE = path.resolve(__dirname, "..", "knowledge", "sre-learning-path");
|
||||
const MODDIR = path.join(SITE, "modules");
|
||||
const css = fs.readFileSync(path.join(SITE, "assets", "doc.css"), "utf8");
|
||||
const cssClasses = new Set([...css.matchAll(/\.([a-zA-Z][a-zA-Z0-9_-]*)/g)].map(m => m[1]));
|
||||
|
||||
/* 只在复合选择器里出现、单独扫描时会误报的名字 */
|
||||
const KNOWN = new Set(["prev", "current"]);
|
||||
|
||||
const classesOf = dir => {
|
||||
const set = new Set();
|
||||
for (const f of fs.readdirSync(path.join(MODDIR, dir))) {
|
||||
if (!f.endsWith(".html")) continue;
|
||||
const html = fs.readFileSync(path.join(MODDIR, dir, f), "utf8");
|
||||
for (const m of html.matchAll(/class="([^"]+)"/g)) {
|
||||
for (const t of m[1].split(/\s+/)) if (t) set.add(t);
|
||||
}
|
||||
}
|
||||
return set;
|
||||
};
|
||||
|
||||
const all = fs.readdirSync(MODDIR, { withFileTypes: true })
|
||||
.filter(d => d.isDirectory()).map(d => d.name).sort();
|
||||
const baseline = new Set();
|
||||
for (const d of all.filter(x => /^s[01]-/.test(x))) {
|
||||
for (const t of classesOf(d)) baseline.add(t);
|
||||
}
|
||||
|
||||
const targets = process.argv.slice(2).length
|
||||
? process.argv.slice(2)
|
||||
: all.filter(x => /^s[23]-/.test(x));
|
||||
|
||||
console.log(`基线:阶段 0/1 共 ${baseline.size} 种 class(来自 ${all.filter(x => /^s[01]-/.test(x)).length} 个模块)\n`);
|
||||
let bad = 0;
|
||||
for (const d of targets) {
|
||||
const set = classesOf(d);
|
||||
const alien = [...set].filter(t => !baseline.has(t) && !cssClasses.has(t) && !KNOWN.has(t));
|
||||
const extra = [...set].filter(t => !baseline.has(t) && cssClasses.has(t));
|
||||
if (alien.length) bad++;
|
||||
console.log(`${alien.length ? "✗" : "✓"} ${d}:${set.size} 种 class` +
|
||||
(alien.length ? ` —— 未定义样式:${alien.join(", ")}` : "") +
|
||||
(extra.length ? `(doc.css 中存在但既有页面未用过:${extra.join(", ")})` : ""));
|
||||
}
|
||||
console.log(bad ? `\n有 ${bad} 个模块使用了自创样式` : "\nOK 新页面只使用既有样式");
|
||||
process.exit(bad ? 1 : 0);
|
||||
Reference in New Issue
Block a user