#!/usr/bin/env node /* ========================================================================== VLoop 项目学习 · 页面自检 用法:node tools/check-pages.js [--allow-empty] --allow-empty(骨架期):内容量相关的要求(正文字数、代码块数量、提示框、 表格/卡片、meta 描述长度)降级为提示,只强制结构与链接正确。 内容补齐后去掉该参数,恢复为与其它站点一致的严格模式。 站点分三级页面,检查项按级别区分: 所有页面:title / article / #chapters 侧栏 / partnav 顶栏篇章导航 / doc.css / doc.js / themeBtn / 站内链接不跑出本站 目录页 index.html:AUTO:kpis / AUTO:partcards(6 张)/ AUTO:prog / 「开始阅读」/ 目录页页脚 篇章页 part-N.html:AUTO:hero / AUTO:cards(张数 = 本篇章数)/ AUTO:prog / 「篇 N / 6」定位条 / 上一篇下一篇 / 篇章页页脚 章节页 NN-*.html:h2 / 小节 id 前缀 / 章位条 / 上一章下一章 / 章节页页脚 / 当前章 active / 侧栏小节数 = 正文 h3 数 通用:标签配对、死链、锚点、目录树列全 22 章并按篇分组、 顶栏篇章导航 6 个链接且当前篇高亮 ========================================================================== */ "use strict"; const fs = require("fs"); const path = require("path"); const ALLOW_EMPTY = process.argv.includes("--allow-empty"); const root = path.resolve(__dirname, ".."); const problems = []; const info = []; const must = (c, m) => { if (!c) problems.push(m); }; const soft = (m) => { if (ALLOW_EMPTY) info.push("○ " + m); else problems.push(m); }; const read = (p) => fs.readFileSync(p, "utf8"); const stripTags = (s) => s.replace(/<[^>]+>/g, ""); const norm = (s) => s.replace(/\s+/g, "").length; /* 正文字数:只看
内的手写内容——排除代码块,也排除 build-nav 生成的 导航(翻页 / 页脚 / 章位条),否则生成出来的文字会把篇幅算进去。 */ const bodyChars = (html) => { const art = (html.match(/
([\s\S]*)<\/article>/) || [, ""])[1] .replace(//g, " ") .replace(/