feat: VLoop 项目学习站上线骨架与前言两章(项目全景、学习路线)

This commit is contained in:
2026-10-19 11:16:29 +08:00
parent f3a7596baf
commit c6a917d6a7
37 changed files with 5578 additions and 1 deletions

228
project/VLoop/tools/SPEC.md Normal file
View File

@@ -0,0 +1,228 @@
# VLoop 项目学习 · 章节写作规范与大纲
> 本文件是**写作规范**;章节与小节的**逐条清单**在 [`outline.json`](outline.json) 里,它是骨架的唯一数据源。
> `tools/build-nav.js` 会用 outline.json 与页面里的 `<h3 id>` 双向核对,任何一边漂移都会直接报错并停止改写。
---
## 一、站点定位
围绕 **VLoop**(Go module `feedsystem_video_go`)这套短视频 Feed 系统的**项目学习站**:
不是 API 手册,也不是源码注释,而是回答「这个项目为什么这么写、换我会怎么答」的问题。
读者画像:准备用这个项目做简历主项目 / 面试主线的后端工程师。
阅读顺序:先建立地图(篇 0)→ 补前置(篇 1)→ 追源码(篇 2)→ 练表达(篇 3)→ 排故障(篇 4)→ 查速查表(篇 5)。
与仓库内其它站点的分工:`knowledge/` 放横向单点知识(Docker / Linux / Nginx),本站只放**这一个项目**的纵向拆解。
## 二、文件与目录约定
```text
project/VLoop/
├── index.html # 学习地图(一级页面):标题区、KPI、六个篇章入口卡片、搜索与总进度
├── part-0.html … part-5.html # 篇章页(一级页面):篇导语 + 本篇章节卡片 + 本篇进度
├── 01-overview.html # 章节页,NN- 前缀决定章号
│ … 22-cheatsheet.html
├── assets/
│ ├── doc.css # 共用样式(与其它知识站点同一套设计变量,品牌色 #0f9d6e)
│ └── doc.js # 顶栏/侧栏高亮、主题切换、代码块增强、勾选与进度、搜索
├── tools/
│ ├── outline.json # ★ 骨架唯一数据源:篇 / 章 / 小节
│ ├── build-nav.js # 生成顶栏篇章导航、侧栏目录树、篇页导语与卡片、翻页、页脚
│ ├── check-pages.js # 自检:结构 / 链接 / 锚点 / 目录树 / 内容量
│ └── SPEC.md # 本文件:写作规范与大纲
└── README.md # 目录结构、工具用法与维护流程
```
三级页面:`index.html`(学习地图)→ `part-N.html`(篇章页)→ `NN-slug.html`(章节页)。
**篇章是一级导航,直接摆在顶栏**,六个篇各有一个独立页面;篇号与章号全部由 `outline.json` 驱动,
页面里不写死任何跨页链接。
命名与编号:章节文件一律 `NN-slug.html`,`NN` 从 `01` 连续递增,**章号 = 文件名前两位**。
小节 id 一律 `sec-<章号>-<序号>`,序号从 1 连续(`sec-9-4` 表示第 9 章第 4 节)。
## 三、唯一数据源:outline.json
```jsonc
{
"site": { "name": "…", "themeKey": "vloop-study-v1:theme", "repoUrl": "…" },
"levels": [ { "id": "L1", "name": "能跑能演示", "goal": "…" } ], // 五级目标,供第 2 章引用
"parts": [
{
"no": "0",
"name": "前言 · 先建立地图", // 侧栏只取 · 之前的部分作为篇名
"note": "篇导语,目录页卡片组上方显示",
"chapters": [
{
"file": "01-overview.html",
"title": "项目全景:这个 Feed 系统是什么", // 必须与页面 <h2> 文本完全一致
"desc": "…", // 与页面 <meta name="description"> 一致
"keywords": "…",
"level": "L1", // 目录页卡片右上角的能力等级标签
"sections": [ { "id": "sec-1-1", "title": "1.1 一句话定位:它解决什么问题" } ]
}
]
}
]
}
```
**改大纲的正确姿势**:先改 `outline.json`,再改对应页面的 `<h2>` / `<h3>`,最后跑 `node tools/build-nav.js`。
反过来(只改页面不改大纲)会在 build-nav 的核对阶段报错——这是有意设计的护栏。
## 四、页面骨架与固定区块
三类页面都由 build-nav 自动填充固定区块,写作时**不要手改**。
**所有页面**
| 位置 | 占位 | 由谁生成 |
|---|---|---|
| 顶栏篇章导航 | `<nav class="partnav" id="partnav"></nav>` | 「学习地图 + 篇 0~篇 5」,当前篇高亮 |
**侧栏目录树**(`<nav id="chapters"></nav>`)按页面级别收窄,这是有意的设计:
| 页面 | 侧栏内容 |
|---|---|
| 学习地图 `index.html` | 唯一能看到全貌的地方:六个篇分组,列全 22 章 |
| 篇章页 `part-N.html` | **只列本篇自己的章**,顶部一条范围条(`篇 N 篇名` + 「全部篇章 →」回到学习地图) |
| 章节页 `NN-*.html` | 同上,只列本篇的章;当前章高亮并展开自己的小节 |
跨篇跳转交给顶栏的篇章导航,侧栏只承担「在本篇里横向移动」的职责,
避免每翻一章都要在一份 22 章的长目录里重新找位置。
**章节页**
| 位置 | 占位 | 由谁生成 |
|---|---|---|
| 正文顶部定位条 | `<p class="chapnav"></p>` | 「VLoop 项目学习 · 篇 N 篇名 · 第 N / 22 章」 |
| 文末翻页 | `<nav class="pager"></nav>` | 上一章 / 下一章(跨篇连续) |
| 页脚 | `<p class="foot"></p>` | 本章标题 + 学习地图 / 本篇 / 速查与自测 |
作者只手写 `<article>` 内部:`<div class="lead">` → 若干 `<h3 id="sec-N-x">` → 正文。
**篇章页**
| 位置 | 占位 | 由谁生成 |
|---|---|---|
| 定位条 | `<p class="chapnav"></p>` | 「VLoop 项目学习 · 篇 N / 6」 |
| 篇导语 | `<!-- AUTO:hero -->` | 篇号、篇名、篇导语、章号区间、章数/小节数、能力等级 |
| 章节卡片 | `<!-- AUTO:cards -->` | 本篇每章一张卡:勾选已读 + 章号 + 标题 + 等级 + 描述 + 可展开小节 |
| 本篇进度 | `<!-- AUTO:prog -->` | `<div class="progwrap" data-chapters="5,6,…">` |
| 翻页 / 页脚 | `<nav class="pager">` / `<p class="foot">` | 上一篇 / 下一篇 + 本篇页脚 |
篇章页还带一条工具栏(搜索、展开全部小节、清空进度、打印),由 `doc.js` 接管;
搜索范围是本篇的章节卡片,进度只统计本篇的章。
**学习地图页**
| 位置 | 占位 | 由谁生成 |
|---|---|---|
| 指标 | `<!-- AUTO:kpis -->` | 篇数 / 章数 / 小节数 / 代码段数 / 正文字数 |
| 篇章入口卡片 | `<!-- AUTO:partcards -->` | 一篇一张卡:篇号、篇名、篇导语、章数/小节数、能力等级、已读进度 |
| 总进度 | `<!-- AUTO:prog -->` | `data-chapters` 为全部 22 章 |
| 翻页 / 页脚 | `<nav class="pager">` / `<p class="foot">` | 「开始阅读」+ 全站页脚 |
已读进度存在 `localStorage` 的 `vloop-study-v1:progress` 里,键是章号;
篇章页写入、学习地图按篇汇总,两处共用同一份记录。
## 五、写作规范
### 5.1 每章的硬性要求(`check-pages.js` 严格模式会逐条检查)
- **开头一段 `.lead`**:`<b>这一章解决什么:</b>` 起头,一到三句话说清本章要回答的问题;
- **至少 3 个小节**(`<h3 id="sec-N-x">`),小节标题与 outline.json 一致;
- **至少 2 个代码块**,每个都必须有 `data-lang`,建议再加 `data-name` 说明来源;
- **至少 1 个提示框**(`.box`)与 **至少 1 个表格或卡片组**(`.tablewrap` / `.cards`);
- **正文不少于 2200 字**(不含代码块内的字符)。
### 5.2 事实必须可核对
这是本站与普通教程最大的区别:**每个结论都要落到能被人复查的位置**。
- 讲实现 → 给 `文件路径:行号`,例如 `backend/internal/feed/service.go:151`;
- 讲行为 → 给可复现的命令与**真实输出**,并注明运行环境(Go 版本 / 容器版本 / 是否代理);
- 讲配置 → 给配置文件里的键名与默认值,不要写「一般默认是……」。
三类标记的用法:
| 标记 | 用在哪 |
|---|---|
| `.box note` | 需要先建立的背景概念 |
| `.box tip` | 可直接抄的做法、经验值 |
| `.box warn` / `.box danger` | 坑、反直觉结论、会造成数据损坏的操作 |
| `.box ok` | 验证通过的做法 |
| `.box case` | 完整案例、真实故障复盘 |
### 5.3 代码块
```html
<pre data-lang="go" data-name="backend/internal/feed/service.go:151-160">func (f *FeedService) ListLatest(…) { … }</pre>
```
- `data-lang` 允许列表:`bash shell sh console text yaml yml json dockerfile go javascript js
typescript ts python java sql nginx ini toml conf powershell http makefile dockerignore properties xml csv promql vue html`;
- 块内 `<` 必须转义为 `&lt;`(自检会拦);
- 只贴**能说明问题的那几行**,长文件用注释标注省略位置。
### 5.4 三条叙述纪律
1. **先结论后展开**:每节第一段就把答案说了,后面才是论证。
2. **区分「设计如此」与「现状是坑」**:这个项目有一批已记录的已知问题(见项目内 `docs/ISSUES-REPORT.md`)。
讲课时要明确标注「这是有意取舍」还是「这是待修缺陷」,不要把缺陷讲成亮点,也不要把取舍当成 bug。
3. **不编造**:没有实测过的数字、没有读过的文件,宁可不写。拿不准就写「源码中未见实现」。
## 六、大纲(6 篇 / 22 章 / 137 小节)
| 篇 | 章 | 文件 | 标题 | 小节 | 能力等级 |
|---|---|---|---|---|---|
| 0 前言 | 1 | `01-overview.html` | 项目全景:这个 Feed 系统是什么 | 6 | L1 |
| 0 前言 | 2 | `02-roadmap.html` | 学习路线:五级目标、七天节奏与最终产出 | 6 | L1 |
| 1 知识学习 | 3 | `03-basics-go.html` | Go 与框架基础:Gin / GORM / 分层与依赖注入 | 6 | L1 |
| 1 知识学习 | 4 | `04-basics-infra.html` | 基础设施基础:MySQL / Redis / RabbitMQ / JWT / Compose | 6 | L1 |
| 2 项目拆解 | 5 | `05-architecture.html` | 工程结构与双进程:API 与 Worker 如何分工 | 6 | L2 |
| 2 项目拆解 | 6 | `06-datamodel.html` | 数据模型与表关系:十张表怎么设计 | 7 | L2 |
| 2 项目拆解 | 7 | `07-auth.html` | 账号与鉴权:双 Token、会话撤销与限流 | 6 | L2 |
| 2 项目拆解 | 8 | `08-video.html` | 视频发布:上传、封面、话题标签与 Outbox | 6 | L2 |
| 2 项目拆解 | 9 | `09-feed.html` | Feed 流:三级缓存、冷热分离与游标分页 | 7 | L3 |
| 2 项目拆解 | 10 | `10-popularity.html` | 热榜与热度:分钟窗口、快照合并与稳定分页 | 5 | L3 |
| 2 项目拆解 | 11 | `11-interaction.html` | 点赞 / 评论 / 关注:三条写路径的差异与降级 | 7 | L3 |
| 2 项目拆解 | 12 | `12-mq.html` | 消息队列与可靠性:连接管理器、拓扑重放与消费循环 | 7 | L3 |
| 2 项目拆解 | 13 | `13-chunk.html` | 分片上传:会话、校验与断点续传 | 6 | L2 |
| 2 项目拆解 | 14 | `14-notify.html` | 通知、SSE 与私信:实时推送链路 | 6 | L2 |
| 2 项目拆解 | 15 | `15-cache-limit.html` | 缓存与限流:键空间、TTL、分布式锁与窗口算法 | 6 | L3 |
| 2 项目拆解 | 16 | `16-observability.html` | 可观测性与部署:探针、pprof、Compose、start.sh 与 CI | 7 | L2 |
| 3 面试模拟 | 17 | `17-interview-core.html` | 高频追问:按模块整理的题库 | 8 | L3 |
| 3 面试模拟 | 18 | `18-interview-narrative.html` | 项目讲述:两分钟自述、简历亮点与追问引导 | 5 | L3 |
| 3 面试模拟 | 19 | `19-interview-deep.html` | 深水区:并发、幂等、一致性与容量估算 | 6 | L3 |
| 4 场景还原 | 20 | `20-scenarios-e2e.html` | 三条核心链路端到端还原 | 5 | L3 |
| 4 场景还原 | 21 | `21-scenarios-failure.html` | 故障场景:MQ 断连、Redis 失效、DB 抖动与消息重复 | 7 | L3 |
| 5 收尾 | 22 | `22-cheatsheet.html` | 速查表与自测清单 | 6 | L4 |
逐个小节标题见 `outline.json`。**新增 / 调整小节时,先改 outline.json 再改页面**。
## 七、生成与自检流程
```bash
cd project/VLoop
node tools/build-nav.js # 核对大纲 → 重建顶栏、侧栏、篇页导语与卡片、翻页、页脚
node tools/check-pages.js --allow-empty # 骨架期:只强制结构与链接
node tools/check-pages.js # 内容补齐后:恢复严格的字数与组件检查
```
- `build-nav.js` **幂等**,可反复运行;一旦发现页面与大纲不一致(或篇章页缺失)会立即退出(退出码 1)且不写盘。
- `check-pages.js` 检查:三级页面的结构差异、顶栏篇章导航的 6 个链接与当前篇高亮、标签配对、死链、
锚点、当前章 active、侧栏小节数 = 正文 h3 数、目录树是否列全 22 章、篇章页卡片张数 = 本篇章数;
严格模式再加字数、代码块数量与 `data-lang`、提示框、表格/卡片、meta 描述长度。
- 全站完成后,回到仓库根目录跑一次导航页自检:`node tools/check-portal.js`。
## 八、章节写作清单(每章交稿前自查)
- [ ] `.lead` 说清了「这一章解决什么」
- [ ] 小节标题与 `outline.json` 完全一致,id 为 `sec-N-x`
- [ ] 每个结论都能指到 `文件:行号` 或可复现命令
- [ ] 至少 2 个代码块,都带 `data-lang`,块内 `<` 已转义
- [ ] 至少 1 个提示框 + 1 个表格或卡片组
- [ ] 明确区分「有意取舍」与「已知缺陷」,并尽量指回项目内的记录
- [ ] 正文 ≥ 2200 字;删掉所有 `class="tbd"` 占位
- [ ] `node tools/build-nav.js` 与 `node tools/check-pages.js` 均无报错

View File

@@ -0,0 +1,359 @@
#!/usr/bin/env node
/* ==========================================================================
VLoop 项目学习 · 页面骨架生成器
用法:node tools/build-nav.js
本站分三级页面:
目录页 index.html 学习地图 + 六个篇章入口卡片
篇章页 part-N.html 一篇的导语 + 该篇的章节卡片(六个篇)
章节页 NN-slug.html 一章正文(二十二章)
数据来源:
tools/outline.json ← 篇 / 章 / 小节 的声明(骨架的唯一来源)
各页面的 <h3 id> ← 只用来核对「页面是否与大纲一致」,不反向覆盖大纲
重写的占位区块:
所有页面:<nav class="partnav"> 顶栏篇章导航(当前篇高亮)
<nav id="chapters"> 侧栏目录树(按篇分组,当前章展开小节)
篇章页: <!-- AUTO:hero --> 篇章导语(篇号 / 篇名 / 篇导语 / 章数小节数)
<!-- AUTO:cards --> 该篇的章节卡片
<!-- AUTO:prog --> 本篇已读进度条
<p class="chapnav"> 「篇 N / 6」定位条
<nav class="pager"> 上一篇 / 下一篇
目录页: <!-- AUTO:kpis --> 篇 / 章 / 小节 / 代码 / 字数
<!-- AUTO:partcards --> 六个篇章入口卡片
<!-- AUTO:prog --> 总体已读进度条
<nav class="pager"> 「开始阅读」
页脚: <p class="foot"> 三种页面各自的页脚
写正文时只写 <article> 里的内容,骨架由本脚本统一生成;调整大纲先改 outline.json
与页面标题,再执行本脚本。幂等、可重复运行。
========================================================================== */
"use strict";
const fs = require("fs");
const path = require("path");
const ROOT = path.resolve(__dirname, "..");
const PLAN = JSON.parse(fs.readFileSync(path.join(__dirname, "outline.json"), "utf8"));
const S = PLAN.site;
const TOTAL = PLAN.parts.reduce((n, p) => n + p.chapters.length, 0);
const PART_PAGE = (no) => `part-${no}.html`;
const esc = (s) => String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;")
.replace(/>/g, "&gt;").replace(/"/g, "&quot;");
const stripTags = (s) => s.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
const decode = (s) => s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"')
.replace(/&#39;/g, "'").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&");
const plain = (s) => decode(stripTags(s));
const shortPart = (name) => name.split("·")[0].trim();
/* ---------------------------- 1. 采集与核对 ---------------------------- */
const chapters = [];
const problems = [];
for (const part of PLAN.parts) {
const pf = PART_PAGE(part.no);
if (!fs.existsSync(path.join(ROOT, pf))) problems.push(`${pf}: 篇章页不存在`);
for (const c of part.chapters) {
const file = c.file;
if (!fs.existsSync(path.join(ROOT, file))) { problems.push(`${file}: 文件不存在`); continue; }
const html = fs.readFileSync(path.join(ROOT, file), "utf8");
const num = parseInt(file.slice(0, 2), 10);
const h2 = html.match(/<h2 id="([^"]+)">([\s\S]*?)<\/h2>/);
if (!h2) { problems.push(`${file}: 找不到 <h2 id="...">章标题</h2>`); continue; }
const title = plain(h2[2].replace(/<span class="n">\d+<\/span>/, ""));
if (title !== c.title) {
problems.push(`${file}: 章标题与 outline.json 不一致\n 页面:${title}\n 大纲:${c.title}`);
}
/* 小节以页面 h3 为准,但必须与大纲逐条对齐(数量 + id + 标题) */
const secs = [...html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)]
.map((m) => ({ id: m[1], label: plain(m[2]) }));
if (secs.length !== c.sections.length) {
problems.push(`${file}: 小节数 ${secs.length} ≠ 大纲 ${c.sections.length}`);
} else {
c.sections.forEach((s, i) => {
if (secs[i].id !== s.id) problems.push(`${file}: 第 ${i + 1} 个小节 id "${secs[i].id}" ≠ 大纲 "${s.id}"`);
if (secs[i].label !== s.title) {
problems.push(`${file}: 小节 "${s.id}" 标题与大纲不一致\n 页面:${secs[i].label}\n 大纲:${s.title}`);
}
});
}
const article = (html.match(/<article>([\s\S]*)<\/article>/) || [, ""])[1];
/* 正文字数:排除代码块,也排除本脚本生成的导航(翻页 / 页脚 / 章位条) */
const bodyText = article
.replace(/<pre[\s\S]*?<\/pre>/g, " ")
.replace(/<nav class="pager">[\s\S]*?<\/nav>/g, " ")
.replace(/<p class="foot">[\s\S]*?<\/p>/g, " ")
.replace(/<p class="chapnav">[\s\S]*?<\/p>/g, " ");
chapters.push({
num, file, title, part, sections: secs,
desc: plain((html.match(/<meta name="description" content="([^"]*)"/) || [, ""])[1]),
level: c.level || "",
pres: (html.match(/<pre[\s\S]*?<\/pre>/g) || []).length,
chars: plain(bodyText).replace(/\s+/g, "").length,
todo: (html.match(/class="tbd"/g) || []).length
});
}
}
if (problems.length) {
console.error(`大纲与页面不一致(${problems.length} 处),已停止改写:`);
problems.forEach((p) => console.error(" - " + p));
process.exit(1);
}
const parts = PLAN.parts.map((p) => ({
...p,
chapters: p.chapters.map((c) => chapters.find((x) => x.file === c.file)).filter(Boolean)
}));
/* 章的 part 必须指回「富化后」的篇对象,否则 ctx.part.chapters 拿到的是大纲里的
原始章节(没有 num / pres / chars),渲染出来章号会是 undefined。 */
for (const p of parts) for (const ch of p.chapters) ch.part = p;
const totalSecs = chapters.reduce((n, c) => n + c.sections.length, 0);
const totalPres = chapters.reduce((n, c) => n + c.pres, 0);
const totalChars = chapters.reduce((n, c) => n + c.chars, 0);
const totalTodo = chapters.reduce((n, c) => n + c.todo, 0);
const allNums = chapters.map((c) => c.num).join(",");
/* ---------------------------- 2. 区块生成 ---------------------------- */
function partnav(ctx) {
const rows = [`<a class="home${ctx.kind === "index" ? " on" : ""}" href="index.html">学习地图</a>`,
`<span class="pn-sep"></span>`];
for (const p of parts) {
const on = ctx.part && String(ctx.part.no) === String(p.no);
rows.push(`<a href="${PART_PAGE(p.no)}"${on ? ' class="on"' : ""}>篇 ${p.no} ${esc(shortPart(p.name))}</a>`);
}
return `<nav class="partnav" id="partnav">${rows.join("")}</nav>`;
}
function chapterRow(ch, ctx) {
const isCur = ctx.kind === "chapter" && ch.num === ctx.chapter.num;
if (!isCur) {
return `<a class="toc-a" href="${ch.file}"><i class="cn">${ch.num}</i>${esc(ch.title)}</a>`;
}
const sub = ch.sections.length
? `<div class="subnav current">${ch.sections
.map((s) => `<a class="toc-a lv3" href="#${s.id}">${esc(s.label)}</a>`).join("")}</div>`
: "";
return `<span class="toc-a active" aria-current="page"><i class="cn">${ch.num}</i>${esc(ch.title)}</span>` + sub;
}
function navTree(ctx) {
/* 学习地图:全站目录,六个篇分组列出全部章节——它是唯一「看得见全貌」的地方 */
if (ctx.kind === "index") {
const rows = [];
for (const p of parts) {
rows.push(`<div class="toc-part"><a href="${PART_PAGE(p.no)}">篇 ${p.no} · ${esc(shortPart(p.name))}</a></div>`);
for (const ch of p.chapters) rows.push(chapterRow(ch, ctx));
}
return `<nav id="chapters">${rows.join("")}</nav>`;
}
/* 篇章页与章节页:侧栏只列本篇自己的章,顶部一条「本篇 / 全部篇章」的范围条 */
const p = ctx.part;
const rows = [
`<div class="toc-scope">` +
`<span class="ts-label">篇 ${p.no}</span><span class="ts-name">${esc(shortPart(p.name))}</span>` +
`<a class="ts-all" href="index.html">全部篇章 →</a>` +
`</div>`
];
for (const ch of p.chapters) rows.push(chapterRow(ch, ctx));
return `<nav id="chapters">${rows.join("")}</nav>`;
}
function chapnav(ctx) {
if (ctx.kind === "part") {
return ` <a href="index.html">${esc(S.name)}</a>\n` +
` <span>·</span>\n` +
` <span>篇 <b class="pos">${ctx.part.no}</b> / ${parts.length}</span>`;
}
const p = ctx.chapter.part;
return ` <a href="index.html">${esc(S.name)}</a>\n` +
` <span>·</span>\n` +
` <a href="${PART_PAGE(p.no)}">篇 ${p.no} ${esc(shortPart(p.name))}</a>\n` +
` <span>·</span>\n` +
` <span>第 <b class="pos">${ctx.chapter.num}</b> / ${TOTAL} 章</span>`;
}
function pagerLinks(prev, next, kPrev, kNext, doneText) {
const a = (item, cls, k) => item
? ` <a class="${cls}" href="${item.href}"><span class="k">${k}</span><span class="v">${item.label}</span></a>`
: ` <a class="${cls} disabled"><span class="k">${k}</span><span class="v">${doneText}</span></a>`;
return a(prev, "prev", kPrev) + "\n" + a(next, "next", kNext);
}
function pager(ctx) {
if (ctx.kind === "index") {
const first = chapters[0];
return ` <a class="next" href="${first.file}"><span class="k">开始阅读 →</span><span class="v">第 ${first.num} 章 · ${esc(first.title)}</span></a>`;
}
if (ctx.kind === "part") {
const i = parts.indexOf(ctx.part);
const mk = (p) => p && { href: PART_PAGE(p.no), label: `篇 ${p.no} · ${esc(shortPart(p.name))}` };
return pagerLinks(mk(parts[i - 1]), mk(parts[i + 1]), "← 上一篇", "下一篇 →", "没有更多了");
}
const i = chapters.indexOf(ctx.chapter);
const mk = (c) => c && { href: c.file, label: `第 ${c.num} 章 · ${esc(c.title)}` };
return pagerLinks(mk(chapters[i - 1]), mk(chapters[i + 1]), "← 上一章", "下一章 →", "没有更多了");
}
function foot(ctx) {
if (ctx.kind === "index") {
return ` ${esc(S.name)} · 共 ${parts.length} 篇 ${TOTAL} 章 ${totalSecs} 个小节` +
`${totalTodo ? ` · 其中 ${totalTodo} 个小节待撰写` : ` · ${totalPres} 段代码`}<br>\n` +
` <a href="${esc(S.repoUrl)}">${esc(S.repo)}</a> · <a href="index.html">学习地图</a>`;
}
if (ctx.kind === "part") {
return ` ${esc(S.name)} · 篇 ${ctx.part.no} ${esc(ctx.part.name)}<br>\n` +
` <a href="index.html">学习地图</a> · ${ctx.part.chapters.length} 章 · ` +
`${ctx.part.chapters.reduce((n, c) => n + c.sections.length, 0)} 个小节`;
}
const c = ctx.chapter;
return ` ${esc(S.name)} · 第 ${c.num} 章 ${esc(c.title)}<br>\n` +
` <a href="index.html">学习地图</a> · <a href="${PART_PAGE(c.part.no)}">篇 ${c.part.no} ${esc(shortPart(c.part.name))}</a>` +
` · <a href="22-cheatsheet.html">速查与自测</a>`;
}
function kpis() {
const wan = (totalChars / 10000).toFixed(1);
return [
`<div class="kpi"><b>${parts.length}</b><span>个篇章 · 递进式学习路径</span></div>`,
`<div class="kpi"><b>${TOTAL}</b><span>章 · 从全景到速查</span></div>`,
`<div class="kpi"><b>${totalSecs}</b><span>个小节骨架</span></div>`,
`<div class="kpi"><b>${totalPres}</b><span>段可复制代码</span></div>`,
`<div class="kpi"><b>${wan} 万</b><span>字正文</span></div>`
].join("\n ");
}
function partcards() {
return parts.map((p) => {
const nums = p.chapters.map((c) => c.num);
const secs = p.chapters.reduce((n, c) => n + c.sections.length, 0);
const lv = [...new Set(p.chapters.map((c) => c.level).filter(Boolean))].sort();
return ` <div class="partcard" data-chapters="${nums.join(",")}">
<div class="pc-head">
<span class="pc-no">篇 ${p.no}</span>
<a class="pc-name" href="${PART_PAGE(p.no)}">${esc(p.name)}</a>
</div>
<p class="pc-note">${esc(p.note || "")}</p>
<div class="pc-meta">
<span><b>${nums.length}</b> 章</span>
<span><b>${secs}</b> 小节</span>
${lv.length ? `<span>${lv.join(" / ")}</span>` : ""}
<span data-partprog>已读 0 / ${nums.length}</span>
</div>
<a class="pc-go" href="${PART_PAGE(p.no)}">进入本篇 →</a>
</div>`;
}).join("\n");
}
function cardsOf(part) {
return part.chapters.map((ch) => {
const search = [ch.title, ch.desc, ch.level, ch.sections.map((s) => s.label).join(" ")]
.join(" ").toLowerCase();
const secs = ch.sections.map((s) =>
`<a href="${ch.file}#${s.id}">${esc(s.label)}</a>`).join("");
return ` <div class="chapcard" data-search="${esc(search)}">
<div class="cc-head">
<input type="checkbox" data-ch="${ch.num}" aria-label="标记第 ${ch.num} 章已读">
<span class="cc-no">${ch.num}</span>
<a class="cc-title" href="${ch.file}">${esc(ch.title)}</a>
${ch.level ? `<span class="cc-lv">${esc(ch.level)}</span>` : ""}
<a class="cc-go" href="${ch.file}">进入 →</a>
</div>
<p class="cc-desc">${esc(ch.desc)}</p>
<details class="cc-secs">
<summary>${ch.sections.length} 个小节${ch.todo ? " · 待撰写" : ""} · 展开看知识点</summary>
<div>${secs}</div>
</details>
</div>`;
}).join("\n");
}
function hero(part) {
const nums = part.chapters.map((c) => c.num);
const secs = part.chapters.reduce((n, c) => n + c.sections.length, 0);
const lv = [...new Set(part.chapters.map((c) => c.level).filter(Boolean))].sort();
return ` <!-- AUTO:hero -->
<div class="modhero">
<span class="mh-no">篇 ${part.no} / ${parts.length}</span>
<h1>${esc(part.name)}</h1>
<p class="mh-sub">${esc(part.note || "")}</p>
<div class="mh-meta">
<span>第 <b>${nums[0]}</b>–<b>${nums[nums.length - 1]}</b> 章</span>
<span><b>${nums.length}</b> 章 · <b>${secs}</b> 个小节</span>
${lv.length ? `<span>能力等级 <b>${lv.join(" / ")}</b></span>` : ""}
</div>
</div>
<!-- /AUTO:hero -->`;
}
function prog(nums) {
return ` <!-- AUTO:prog -->
<div class="progwrap" data-chapters="${nums}">
<span>已读</span><div class="bar"><i></i></div><b>0%</b>
</div>
<!-- /AUTO:prog -->`;
}
/* ---------------------------- 3. 写回 ---------------------------- */
const Z = (re, gen, only) => ({ re, gen, only });
const zones = [
Z(/<nav class="partnav"[^>]*>[\s\S]*?<\/nav>/, (ctx) => partnav(ctx)),
Z(/<nav id="chapters">[\s\S]*?<\/nav>/, (ctx) => navTree(ctx)),
Z(/<p class="chapnav">[\s\S]*?<\/p>/, (ctx) => `<p class="chapnav">\n${chapnav(ctx)}\n </p>`, "part|chapter"),
Z(/<!-- AUTO:hero -->[\s\S]*?<!-- \/AUTO:hero -->/, (ctx) => hero(ctx.part), "part"),
Z(/<!-- AUTO:kpis -->[\s\S]*?<!-- \/AUTO:kpis -->/, () => `<!-- AUTO:kpis -->\n ${kpis()}\n <!-- /AUTO:kpis -->`, "index"),
Z(/<!-- AUTO:partcards -->[\s\S]*?<!-- \/AUTO:partcards -->/, () => `<!-- AUTO:partcards -->\n${partcards()}\n <!-- /AUTO:partcards -->`, "index"),
Z(/<!-- AUTO:cards -->[\s\S]*?<!-- \/AUTO:cards -->/, (ctx) => `<!-- AUTO:cards -->\n${cardsOf(ctx.part)}\n <!-- /AUTO:cards -->`, "part"),
Z(/<!-- AUTO:prog -->[\s\S]*?<!-- \/AUTO:prog -->/, (ctx) => prog(ctx.kind === "index"
? allNums : ctx.part.chapters.map((c) => c.num).join(",")), "index|part"),
Z(/<nav class="pager">[\s\S]*?<\/nav>/, (ctx) => `<nav class="pager">\n${pager(ctx)}\n </nav>`),
Z(/<p class="foot">[\s\S]*?<\/p>/, (ctx) => `<p class="foot">\n${foot(ctx)}\n </p>`)
];
const targets = [];
if (fs.existsSync(path.join(ROOT, "index.html"))) {
targets.push({ file: "index.html", ctx: { kind: "index" } });
}
for (const p of parts) {
targets.push({ file: PART_PAGE(p.no), ctx: { kind: "part", part: p } });
}
for (const c of chapters) {
targets.push({ file: c.file, ctx: { kind: "chapter", chapter: c, part: c.part } });
}
for (const t of targets) {
const p = path.join(ROOT, t.file);
let html = fs.readFileSync(p, "utf8");
for (const z of zones) {
if (z.only && !z.only.split("|").includes(t.ctx.kind)) continue;
if (!z.re.test(html)) {
console.error(`${t.file}: 缺少占位区块 ${z.re}`);
process.exit(1);
}
html = html.replace(z.re, z.gen(t.ctx));
}
fs.writeFileSync(p, html, "utf8");
}
/* ---------------------------- 4. 报告 ---------------------------- */
for (const p of parts) {
const secs = p.chapters.reduce((n, c) => n + c.sections.length, 0);
console.log(`${PART_PAGE(p.no).padEnd(12)} 篇 ${p.no} · ${String(p.chapters.length).padStart(2)} 章 · ` +
`${String(secs).padStart(3)} 小节 · ${p.name}`);
}
console.log("");
chapters.forEach((c) => console.log(
`${c.file.padEnd(26)} 第 ${String(c.num).padStart(2)} 章 · ${String(c.sections.length).padStart(2)} 小节 · ` +
`${String(c.pres).padStart(2)} 段代码 · ${String(c.chars).padStart(6)} 字 · ${c.title}`));
console.log(`\n篇 ${parts.length} / 章 ${TOTAL} / 小节 ${totalSecs} / 代码 ${totalPres} 段 / ${(totalChars / 10000).toFixed(1)} 万字` +
`${totalTodo ? `(待撰写 ${totalTodo} 个小节)` : ""},已同步 ${targets.length} 个页面。`);

View File

@@ -0,0 +1,272 @@
#!/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;
/* 正文字数:只看 <article> 内的手写内容——排除代码块,也排除 build-nav 生成的
导航(翻页 / 页脚 / 章位条),否则生成出来的文字会把篇幅算进去。 */
const bodyChars = (html) => {
const art = (html.match(/<article>([\s\S]*)<\/article>/) || [, ""])[1]
.replace(/<pre[\s\S]*?<\/pre>/g, " ")
.replace(/<nav class="pager">[\s\S]*?<\/nav>/g, " ")
.replace(/<p class="foot">[\s\S]*?<\/p>/g, " ")
.replace(/<p class="chapnav">[\s\S]*?<\/p>/g, " ");
return norm(stripTags(art));
};
/* ------------------------------------------------------------ 页面清点 */
const chapterFiles = fs.readdirSync(root).filter((f) => /^\d\d-.*\.html$/.test(f)).sort();
const partFiles = fs.readdirSync(root).filter((f) => /^part-\d+\.html$/.test(f))
.sort((a, b) => parseInt(a.slice(5), 10) - parseInt(b.slice(5), 10));
const hasIndex = fs.existsSync(path.join(root, "index.html"));
const pages = (hasIndex ? ["index.html"] : []).concat(partFiles, chapterFiles);
must(chapterFiles.length >= 5, "章节页数量异常:" + chapterFiles.length);
must(partFiles.length >= 2, "篇章页数量异常:" + partFiles.length);
/* 大纲:用于核对「篇章页里的卡片张数 = 该篇章数」 */
const outlineFile = path.join(__dirname, "outline.json");
const PLAN = fs.existsSync(outlineFile) ? JSON.parse(read(outlineFile)) : null;
must(!!PLAN, "tools/outline.json 不存在或解析失败");
const partChapters = new Map(); // 'part-0.html' -> ['01-overview.html', ...]
const chapterPart = new Map(); // '01-overview.html' -> ['01-overview.html', ...](本篇全部章)
if (PLAN) {
for (const p of PLAN.parts) {
const files = p.chapters.map((c) => c.file);
partChapters.set(`part-${p.no}.html`, files);
for (const cf of files) chapterPart.set(cf, files);
}
must(PLAN.parts.length === partFiles.length,
`outline.json 声明 ${PLAN.parts.length} 篇,磁盘上有 ${partFiles.length} 个篇章页`);
}
/* id 索引,供锚点校验 */
const idIndex = new Map();
for (const f of pages) {
const html = read(path.join(root, f));
idIndex.set(f, new Set([...html.matchAll(/\sid="([^"]+)"/g)].map((m) => m[1])));
}
const partFileSet = new Set(partFiles);
for (const f of pages) {
const html = read(path.join(root, f));
const markup = html.replace(/<script[\s\S]*?<\/script>/g, "");
const kind = f === "index.html" ? "index" : (partFileSet.has(f) ? "part" : "chapter");
must(/<title>[^<]+<\/title>/.test(html), `${f}: 缺少 title`);
must(html.includes("<article>"), `${f}: 缺少 <article>`);
must(html.includes('id="chapters"'), `${f}: 缺少侧栏 #chapters`);
must(html.includes('href="assets/doc.css"'), `${f}: doc.css 路径不对`);
must(html.includes('src="assets/doc.js"'), `${f}: doc.js 路径不对`);
must(html.includes('id="themeBtn"'), `${f}: 缺少主题切换按钮`);
must(!/href="\.\.\//.test(markup), `${f}: 站内链接不应跑出本资料目录`);
/* ---------------- 顶栏篇章导航 ---------------- */
const pnav = markup.match(/<nav class="partnav"[^>]*>([\s\S]*?)<\/nav>/);
must(!!pnav, `${f}: 缺少顶栏篇章导航 .partnav`);
if (pnav) {
const links = (pnav[1].match(/<a [^>]*href="part-\d+\.html"/g) || []).length;
must(links === partFiles.length, `${f}: 顶栏篇章导航有 ${links} 个篇章链接 ≠ ${partFiles.length}`);
must(/href="index\.html"/.test(pnav[1]), `${f}: 顶栏篇章导航缺少返回学习地图的入口`);
const onCount = (pnav[1].match(/\bclass="[^"]*\bon\b[^"]*"/g) || []).length;
must(onCount === 1, `${f}: 顶栏篇章导航应有且只有 1 个高亮项(当前为 ${onCount} 个)`);
if (kind === "index") {
must(/<a class="home on" href="index\.html"/.test(pnav[1]), "index.html: 顶栏「学习地图」未高亮");
} else if (kind === "part") {
const no = f.slice(5, -5);
must(new RegExp(`<a href="part-${no}\\.html" class="on"`).test(pnav[1]),
`${f}: 顶栏未把本篇(篇 ${no})标为高亮`);
}
}
/* 代码块结构(骨架期还没有代码块,data-lang 只在有时校验) */
const pres = markup.match(/<pre[\s\S]*?<\/pre>/g) || [];
pres.forEach((blk, i) => {
must(/data-lang=/.test(blk), `${f}: 第 ${i + 1} 个 <pre> 未标注 data-lang`);
const body = blk.replace(/^<pre[^>]*>/, "").replace(/<\/pre>$/, "");
must(!/</.test(body), `${f}: 第 ${i + 1} 个 <pre> 内有未转义的 <`);
});
/* 标签配对 */
for (const t of ["div", "section", "article", "aside", "nav", "main", "details", "table", "ul", "ol", "li"]) {
const o = (markup.match(new RegExp("<" + t + "(?=[\\s>])", "g")) || []).length;
const c = (markup.match(new RegExp("</" + t + ">", "g")) || []).length;
if (o !== c) problems.push(`${f}: <${t}> 开合不匹配 ${o}/${c}`);
}
/* 链接与锚点 */
for (const l of new Set([...markup.matchAll(/href="(?!https?:|mailto:|#)([^"]+)"/g)].map((m) => m[1]))) {
const [file, hash] = l.split("#");
const target = path.resolve(root, file || f);
if (file && !fs.existsSync(target)) { problems.push(`${f}: 死链 ${l}`); continue; }
const key = file ? path.basename(file) : f;
if (hash && idIndex.has(key) && !idIndex.get(key).has(hash)) problems.push(`${f}: 锚点不存在 ${l}`);
}
for (const l of new Set([...markup.matchAll(/href="#([^"]+)"/g)].map((m) => m[1]))) {
if (!idIndex.get(f).has(l)) problems.push(`${f}: 页内锚点不存在 #${l}`);
}
/* ---------------- 按页面级别检查 ---------------- */
if (kind === "index") {
must(/<!-- AUTO:kpis -->/.test(html), "index.html: 缺少 AUTO:kpis 区块");
must(/<!-- AUTO:partcards -->/.test(html), "index.html: 缺少 AUTO:partcards 区块");
must(/<!-- AUTO:prog -->/.test(html), "index.html: 缺少 AUTO:prog 区块");
const pc = (markup.match(/class="partcard"/g) || []).length;
must(pc === partFiles.length, `index.html: 篇章入口卡片 ${pc} 张 ≠ ${partFiles.length}`);
must(/data-partprog/.test(markup), "index.html: 篇章卡片缺少已读进度位 data-partprog");
const pg = markup.match(/<nav class="pager">([\s\S]*?)<\/nav>/);
must(!!pg && /开始阅读/.test(pg[1]), "index.html: .pager 缺少「开始阅读」入口");
must(!!pg && !/上一章|下一章|上一篇|下一篇/.test(pg[1]), "index.html: .pager 误用了翻页导航");
must(/class="foot">\s*VLoop 项目学习 · 共 \d+ 篇/.test(html.replace(/\n/g, "")), "index.html: 页脚不是目录页页脚");
must(/class="hero"/.test(markup), "index.html: 缺少 .hero 站点标题区");
}
if (kind === "part") {
const no = f.slice(5, -5);
must(/<!-- AUTO:hero -->/.test(html), `${f}: 缺少 AUTO:hero 区块`);
must(/<!-- AUTO:cards -->/.test(html), `${f}: 缺少 AUTO:cards 区块`);
must(/<!-- AUTO:prog -->/.test(html), `${f}: 缺少 AUTO:prog 区块`);
must(/class="modhero"/.test(markup), `${f}: 缺少篇章导语 .modhero`);
must(/data-chapters="[\d,]+"/.test(markup), `${f}: 缺少进度条 data-chapters`);
const expect = partChapters.get(f) || [];
const cards = [...markup.matchAll(/<div class="chapcard"[^>]*>([\s\S]*?)<details/g)]
.map((m) => (m[1].match(/href="([^"]+)"/) || [, ""])[1]);
must(cards.length === expect.length, `${f}: 章节卡片 ${cards.length} 张 ≠ 本篇 ${expect.length} 章`);
for (const cf of expect) {
must(cards.includes(cf), `${f}: 章节卡片缺少 ${cf}`);
}
const cn = markup.match(/<p class="chapnav">([\s\S]*?)<\/p>/);
must(!!cn && new RegExp(`篇 <b class="pos">${no}</b>`).test(cn[1]), `${f}: 定位条不是「篇 ${no} / N」`);
const pg = markup.match(/<nav class="pager">([\s\S]*?)<\/nav>/);
must(!!pg && /上一篇|下一篇/.test(pg[1]), `${f}: .pager 不是篇章页的上一篇/下一篇`);
must(!!pg && !/开始阅读/.test(pg[1]), `${f}: .pager 误用了目录页的「开始阅读」`);
must(new RegExp(`class="foot">\\s*VLoop 项目学习 · 篇 ${no}`).test(html.replace(/\n/g, "")),
`${f}: 页脚不是本篇页脚`);
}
if (kind === "chapter") {
const num = parseInt(f.slice(0, 2), 10);
const h2 = html.match(/<h2 id="([^"]+)">([\s\S]*?)<\/h2>/);
must(!!h2, `${f}: 缺少 h2 章节标题`);
must(html.includes('class="chapnav"'), `${f}: 缺少章节定位条 .chapnav`);
must(html.includes('class="pager"'), `${f}: 缺少上一/下一章 .pager`);
must(html.includes('class="foot"'), `${f}: 缺少页脚 .foot`);
must(html.includes('href="index.html"'), `${f}: 缺少返回学习地图链接`);
must(/class="toc-a active"[^>]*aria-current="page"/.test(html), `${f}: 当前章未标记 active`);
const h3 = [...html.matchAll(/<h3 id="([^"]+)">([\s\S]*?)<\/h3>/g)];
const h3any = (html.match(/<h3[ >]/g) || []).length;
must(h3.length === h3any, `${f}: 有 h3 未补 id(${h3.length}/${h3any})`);
must(h3.length >= 3, `${f}: 小节过少(${h3.length}),至少 3 个`);
for (const m of h3) {
if (!m[1].startsWith(`sec-${num}-`)) problems.push(`${f}: 小节 id "${m[1]}" 应以 sec-${num}- 开头`);
}
const pager = markup.match(/<nav class="pager">([\s\S]*?)<\/nav>/);
must(!!pager && /上一章|下一章/.test(pager[1]), `${f}: .pager 不是章节页的上一/下一章导航`);
must(!!pager && !/开始阅读|上一篇|下一篇/.test(pager[1]), `${f}: .pager 用了别的页面的翻页样式`);
must(new RegExp(`class="foot">\\s*VLoop 项目学习 · 第 ${num} 章`).test(html.replace(/\n/g, "")),
`${f}: 页脚不是本章标题`);
const sub = html.match(/<div class="subnav current">([\s\S]*?)<\/div>/);
must(!!sub, `${f}: 侧栏缺少当前章小节`);
if (sub) {
const n = (sub[1].match(/class="toc-a lv3"/g) || []).length;
must(n === h3.length, `${f}: 侧栏小节数 ${n} ≠ 正文 h3 数 ${h3.length}`);
}
/* 内容量(骨架期降级为提示) */
const desc = (html.match(/<meta name="description" content="([^"]*)"/) || [, ""])[1];
if (desc.trim().length < 20) soft(`${f}: meta description 太短或缺失(${desc.length} 字)`);
if (!/class="box /.test(html)) soft(`${f}: 没有任何 .box 提示框`);
if (!/class="tablewrap"/.test(html) && !/class="cards"/.test(html)) {
soft(`${f}: 既没有表格也没有卡片组`);
}
if (pres.length < 2) soft(`${f}: 代码块过少(${pres.length}),至少 2 个`);
if (bodyChars(html) < 2200) soft(`${f}: 正文过短(约 ${bodyChars(html)} 字),内容需要补充`);
const tbd = (html.match(/class="tbd"/g) || []).length;
if (tbd && tbd !== h3.length) {
soft(`${f}: ${h3.length} 个小节里有 ${tbd} 个仍标记待补充`);
}
}
/* ---------------- 侧栏目录树 ----------------
学习地图:按篇分组列全 22 章,是唯一能看到全貌的目录。
篇章页 / 章节页:只列本篇的章(顶栏负责跨篇跳转),并带一条范围条。 */
const nav = markup.match(/<nav id="chapters">([\s\S]*?)<\/nav>/);
must(!!nav, `${f}: 缺少 #chapters 目录树`);
if (nav) {
const rows = (nav[1].match(/class="toc-a( active)?"/g) || []).length;
if (kind === "index") {
must(rows === chapterFiles.length, `${f}: 目录树章节数 ${rows} ≠ ${chapterFiles.length}`);
const groups = (nav[1].match(/class="toc-part/g) || []).length;
must(groups === partFiles.length, `${f}: 目录树「篇」分组 ${groups} ≠ ${partFiles.length}`);
for (const cf of chapterFiles) {
must(nav[1].includes(`href="${cf}"`), `${f}: 目录树缺少章节 ${cf}`);
}
must(!/class="subnav/.test(nav[1]), `${f}: 目录页不应展开任何章的小节`);
must(!/class="toc-scope/.test(nav[1]), `${f}: 目录页不应有本篇范围条`);
} else {
const expect = kind === "part" ? (partChapters.get(f) || []) : (chapterPart.get(f) || []);
must(rows === expect.length, `${f}: 侧栏只应列本篇 ${expect.length} 章,实际 ${rows}`);
for (const cf of expect) {
if (cf === f) continue;
must(nav[1].includes(`href="${cf}"`), `${f}: 侧栏缺少本篇章节 ${cf}`);
}
for (const cf of chapterFiles) {
if (cf === f || expect.includes(cf)) continue;
must(!nav[1].includes(`href="${cf}"`), `${f}: 侧栏出现了其它篇的章节 ${cf}`);
}
must(/class="toc-scope"/.test(nav[1]), `${f}: 侧栏缺少本篇范围条 .toc-scope`);
must(/href="index\.html"/.test(nav[1]), `${f}: 侧栏缺少「全部篇章」入口`);
must(!/class="toc-part/.test(nav[1]), `${f}: 侧栏不应再按篇分组`);
}
}
info.push(`${f.padEnd(26)} ~${bodyChars(html)} 字 · 代码块 ${pres.length}`);
}
info.sort((a, b) => a.replace(/^○ /, "").localeCompare(b.replace(/^○ /, "")));
console.log(info.join("\n"));
if (problems.length) {
console.error(`\n✗ 发现 ${problems.length} 个问题:`);
problems.slice(0, 60).forEach((x) => console.error(" - " + x));
process.exit(1);
}
console.log(`\n✓ 结构与链接全部通过(目录页 + ${partFiles.length} 个篇章页 + ${chapterFiles.length} 章,共 ${pages.length} 个页面)` +
(ALLOW_EMPTY ? "\n○ 当前为骨架期(--allow-empty):正文、代码块、提示框与表格尚未撰写,补齐内容后请去掉该参数重跑。"
: "\n 严格模式:内容量与组件构成均已达标。"));

View File

@@ -0,0 +1,407 @@
{
"site": {
"id": "VLoop",
"logo": "VL",
"name": "VLoop 项目学习",
"title": "VLoop 项目学习 · 短视频 Feed 系统源码拆解",
"sub": "Go + Vue 全栈 · 源码拆解 / 面试模拟 / 场景还原",
"desc": "围绕 VLoop(feedsystem_video_go)这套 Go 短视频 Feed 系统的项目学习站:五个篇章、二十二章,从项目全景、前置知识、源码拆解,到面试追问与故障场景还原。",
"repo": "feedsystem_video_go",
"repoUrl": "https://github.com/LeoninCS/feedsystem_video_go",
"themeKey": "vloop-study-v1:theme",
"progressKey": "vloop-study-v1:progress"
},
"levels": [
{ "id": "L1", "name": "能跑能演示", "goal": "起服务、发布视频、刷 Feed、点赞评论、关注、看热度榜" },
{ "id": "L2", "name": "面试级理解", "goal": "讲清双进程、分层、缓存、异步写路径、Outbox 与游标分页" },
{ "id": "L3", "name": "抗追问能力", "goal": "答得住缓存击穿、MQ 故障、消息重复、幂等、冷热分离与降级" },
{ "id": "L4", "name": "可独立复刻", "goal": "关掉文档复刻核心模块:鉴权、发布、Feed、互动、热榜、Worker" },
{ "id": "L5", "name": "抽象成方法论", "goal": "上升为 Feed 系统通用框架:分发模型、缓存层级、异步一致性与演进" }
],
"parts": [
{
"no": "0",
"name": "前言 · 先建立地图",
"note": "先确认目标与学习深度:这个项目是什么、学完能做什么、按什么节奏走。",
"chapters": [
{
"file": "01-overview.html",
"title": "项目全景:这个 Feed 系统是什么",
"desc": "从功能地图、技术栈与工程规模出发,交代双进程与依赖拓扑、三个业务闭环,以及这个项目有意保留的边界与短板。",
"keywords": "短视频,Feed系统,Go,Gin,GORM,MySQL,Redis,RabbitMQ,项目概览",
"level": "L1",
"sections": [
{ "id": "sec-1-1", "title": "1.1 一句话定位:它解决什么问题" },
{ "id": "sec-1-2", "title": "1.2 功能地图:八个模块各能演示什么" },
{ "id": "sec-1-3", "title": "1.3 技术栈与工程规模:先看真实数字" },
{ "id": "sec-1-4", "title": "1.4 双进程与依赖拓扑:谁依赖谁" },
{ "id": "sec-1-5", "title": "1.5 三个业务闭环:发布、互动、刷 Feed" },
{ "id": "sec-1-6", "title": "1.6 这个项目的边界:已知短板与刻意取舍" }
]
},
{
"file": "02-roadmap.html",
"title": "学习路线:五级目标、七天节奏与最终产出",
"desc": "把项目学习拆成五级目标与七天节奏,给出每一级的达标标准、证明方式,以及学完之后应该拿得出的产出清单。",
"keywords": "学习路线,项目学习,节奏表,成熟度,产出清单",
"level": "L1",
"sections": [
{ "id": "sec-2-1", "title": "2.1 五级目标:从能跑能演示到方法论" },
{ "id": "sec-2-2", "title": "2.2 每一级的达标标准与证明方式" },
{ "id": "sec-2-3", "title": "2.3 七天节奏:每天读哪几个模块" },
{ "id": "sec-2-4", "title": "2.4 五种学习模式与这个站点的用法" },
{ "id": "sec-2-5", "title": "2.5 最终产出清单:架构图、链路图与追问答案" },
{ "id": "sec-2-6", "title": "2.6 先把项目跑起来:最小启动路径" }
]
}
]
},
{
"no": "1",
"name": "知识学习 · 补齐前置",
"note": "读源码之前先把会用到的语言、框架与中间件基础补齐,避免边读边查。",
"chapters": [
{
"file": "03-basics-go.html",
"title": "Go 与框架基础:Gin / GORM / 分层与依赖注入",
"desc": "只讲这个项目真正用到的部分:Go 工程组织与并发原语、Gin 的路由与中间件、GORM 的模型与事务,以及四层分层与手工依赖注入的装配方式。",
"keywords": "Go,Gin,GORM,分层架构,依赖注入,singleflight",
"level": "L1",
"sections": [
{ "id": "sec-3-1", "title": "3.1 Go 工程基础:包组织、错误处理与 context" },
{ "id": "sec-3-2", "title": "3.2 Gin:路由分组、中间件与请求绑定" },
{ "id": "sec-3-3", "title": "3.3 GORM:模型、迁移、事务与表达式更新" },
{ "id": "sec-3-4", "title": "3.4 分层模式:Entity → Repository → Service → Handler" },
{ "id": "sec-3-5", "title": "3.5 手工依赖注入:router.go 里的装配顺序" },
{ "id": "sec-3-6", "title": "3.6 并发原语:WaitGroup、RWMutex 与 singleflight" }
]
},
{
"file": "04-basics-infra.html",
"title": "基础设施基础:MySQL / Redis / RabbitMQ / JWT / Compose",
"desc": "把项目依赖的五个基础设施补齐到能看懂源码的程度:索引与唯一约束、缓存键与 ZSET 与 Lua、交换机队列与 Ack、JWT 与吊销,以及 Compose 启动。",
"keywords": "MySQL,Redis,ZSET,Lua,RabbitMQ,死信,JWT,Docker Compose,Feed设计",
"level": "L1",
"sections": [
{ "id": "sec-4-1", "title": "4.1 MySQL:索引、唯一约束与事务边界" },
{ "id": "sec-4-2", "title": "4.2 Redis:缓存键、ZSET、Lua 与分布式锁" },
{ "id": "sec-4-3", "title": "4.3 RabbitMQ:交换机、队列、绑定、Ack 与死信" },
{ "id": "sec-4-4", "title": "4.4 JWT 与可选鉴权:签名、过期与吊销" },
{ "id": "sec-4-5", "title": "4.5 Docker Compose:本地一键起依赖" },
{ "id": "sec-4-6", "title": "4.6 Feed 系统通用设计:推拉结合、冷热分离与游标分页" }
]
}
]
},
{
"no": "2",
"name": "项目拆解 · 追源码",
"note": "本站主体:按十二个模块顺着请求链路把源码读完,每个模块都落到文件、表、键与队列。",
"chapters": [
{
"file": "05-architecture.html",
"title": "工程结构与双进程:API 与 Worker 如何分工",
"desc": "交代目录与包职责、两个二进制的启动顺序、进程职责的真实现状、全量路由与中间件链、配置系统,以及依赖缺失时的降级矩阵。",
"keywords": "双进程,API,Worker,目录结构,路由表,配置,降级",
"level": "L2",
"sections": [
{ "id": "sec-5-1", "title": "5.1 目录结构总览:每个包负责什么" },
{ "id": "sec-5-2", "title": "5.2 双二进制:两个 main 的启动顺序" },
{ "id": "sec-5-3", "title": "5.3 进程职责边界与现状偏差" },
{ "id": "sec-5-4", "title": "5.4 全量路由表与中间件链" },
{ "id": "sec-5-5", "title": "5.5 配置系统:三份 YAML 与环境变量覆盖" },
{ "id": "sec-5-6", "title": "5.6 依赖可选化:Redis / MQ 缺失时的降级矩阵" }
]
},
{
"file": "06-datamodel.html",
"title": "数据模型与表关系:十张表怎么设计",
"desc": "逐张交代十张表的字段、索引与关系,重点讲唯一约束如何当幂等护栏、派生列与索引如何服务 Feed 排序,以及 AutoMigrate 的现状。",
"keywords": "数据模型,表关系,索引,唯一约束,派生字段,AutoMigrate",
"level": "L2",
"sections": [
{ "id": "sec-6-1", "title": "6.1 表清单与整体关系图" },
{ "id": "sec-6-2", "title": "6.2 accounts:凭证、会话与资料字段" },
{ "id": "sec-6-3", "title": "6.3 videos:派生列与三个复合索引" },
{ "id": "sec-6-4", "title": "6.4 likes / comments / social:三类互动关系" },
{ "id": "sec-6-5", "title": "6.5 tags / video_tags:话题的抽取与关联" },
{ "id": "sec-6-6", "title": "6.6 outbox_msgs / messages / notifications:三类消息表" },
{ "id": "sec-6-7", "title": "6.7 AutoMigrate:迁移现状与已知风险" }
]
},
{
"file": "07-auth.html",
"title": "账号与鉴权:双 Token、会话撤销与限流",
"desc": "从注册登录到双 Token 签发与存储,讲清硬软鉴权中间件、密钥 fail-fast 与指纹核对、改名改密登出为什么能立刻踢人,以及刷新链路的代价。",
"keywords": "鉴权,JWT,双Token,Refresh Token,会话撤销,软鉴权",
"level": "L2",
"sections": [
{ "id": "sec-7-1", "title": "7.1 注册与登录:bcrypt 与失败响应现状" },
{ "id": "sec-7-2", "title": "7.2 双 Token 的签发与三处 Redis 键" },
{ "id": "sec-7-3", "title": "7.3 JWT 中间件:硬鉴权与软鉴权" },
{ "id": "sec-7-4", "title": "7.4 密钥治理:fail-fast、指纹与 500/401 分流" },
{ "id": "sec-7-5", "title": "7.5 会话撤销:改名、改密与登出为什么能踢人" },
{ "id": "sec-7-6", "title": "7.6 刷新链路的现状与代价" }
]
},
{
"file": "08-video.html",
"title": "视频发布:上传、封面、话题标签与 Outbox",
"desc": "走完一次视频发布:文件落盘规则、事务里同时写视频与 Outbox 与标签、话题抽取、poller 如何把事件送到时间线,以及删除链路的现状。",
"keywords": "视频发布,上传,Outbox,话题标签,详情缓存,删除",
"level": "L2",
"sections": [
{ "id": "sec-8-1", "title": "8.1 上传链路:视频与封面的落盘规则" },
{ "id": "sec-8-2", "title": "8.2 发布事务:视频 + Outbox + 标签一次写入" },
{ "id": "sec-8-3", "title": "8.3 话题标签:抽取规则与关联写入" },
{ "id": "sec-8-4", "title": "8.4 Outbox 模式:poller 如何投递到时间线" },
{ "id": "sec-8-5", "title": "8.5 详情缓存与主动失效" },
{ "id": "sec-8-6", "title": "8.6 删除链路:未注册的路由与未清理的关联" }
]
},
{
"file": "09-feed.html",
"title": "Feed 流:三级缓存、冷热分离与游标分页",
"desc": "本站最重的一章:五个 Feed 接口各自的游标形状、三级缓存的逐层回源、singleflight 与分布式锁、全局时间线 ZSET 的冷热分水岭与拼接补齐。",
"keywords": "Feed流,三级缓存,冷热分离,游标分页,单飞,时间线",
"level": "L3",
"sections": [
{ "id": "sec-9-1", "title": "9.1 五个 Feed 接口与各自的游标形状" },
{ "id": "sec-9-2", "title": "9.2 三级缓存:L1 → L2 → L3 的逐层回源" },
{ "id": "sec-9-3", "title": "9.3 防击穿:singleflight 与分布式锁" },
{ "id": "sec-9-4", "title": "9.4 全局时间线 ZSET 与冷热分水岭" },
{ "id": "sec-9-5", "title": "9.5 冷热拼接、防重复与 next_time 语义" },
{ "id": "sec-9-6", "title": "9.6 关注流整页缓存与失效时机" },
{ "id": "sec-9-7", "title": "9.7 分页正确性的两个真实缺口" }
]
},
{
"file": "10-popularity.html",
"title": "热榜与热度:分钟窗口、快照合并与稳定分页",
"desc": "讲清热度从哪里来、分钟窗口 ZSET 如何累积、快照如何合并出稳定分页,以及 DB 兜底排序与双轨漂移的成因和影响。",
"keywords": "热榜,热度,Popularity,ZSET,快照,分页",
"level": "L3",
"sections": [
{ "id": "sec-10-1", "title": "10.1 热度事件与 PopularityWorker" },
{ "id": "sec-10-2", "title": "10.2 分钟窗口 ZSET:按分钟分桶累积" },
{ "id": "sec-10-3", "title": "10.3 快照合并与 as_of / offset 稳定分页" },
{ "id": "sec-10-4", "title": "10.4 DB 兜底排序与三元复合游标" },
{ "id": "sec-10-5", "title": "10.5 双轨漂移:DB 热度列为什么恒为 0" }
]
},
{
"file": "11-interaction.html",
"title": "点赞 / 评论 / 关注:三条写路径的差异与降级",
"desc": "把三个互动模块并排比较:点赞的 MQ-first 与唯一索引幂等、评论缺失的幂等、关注反过来的 DB-first,以及各自的降级分支与计数副作用。",
"keywords": "点赞,评论,关注,异步落库,降级,幂等,一致性",
"level": "L3",
"sections": [
{ "id": "sec-11-1", "title": "11.1 点赞:MQ-first 与唯一索引幂等" },
{ "id": "sec-11-2", "title": "11.2 评论:同构写路径与缺失的幂等" },
{ "id": "sec-11-3", "title": "11.3 关注:反过来的 DB-first + MQ 仅通知" },
{ "id": "sec-11-4", "title": "11.4 降级矩阵:MQ 或 Redis 挂掉会发生什么" },
{ "id": "sec-11-5", "title": "11.5 三个 Worker 的落库逻辑与计数副作用" },
{ "id": "sec-11-6", "title": "11.6 提及通知:唯一绕过 MQ 的写入路径" },
{ "id": "sec-11-7", "title": "11.7 读不到自己的写:异步一致性的用户体验" }
]
},
{
"file": "12-mq.html",
"title": "消息队列与可靠性:连接管理器、拓扑重放与消费循环",
"desc": "拆开本项目工程含量最高的一块:五组事件拓扑、连接管理器与连接代、每一代重放拓扑、唯一的消费循环,以及死信与发布确认两处可靠性缺口。",
"keywords": "RabbitMQ,连接管理器,拓扑重放,消费循环,死信,发布确认",
"level": "L3",
"sections": [
{ "id": "sec-12-1", "title": "12.1 五组事件拓扑与路由键" },
{ "id": "sec-12-2", "title": "12.2 连接管理器:为什么需要「连接代」" },
{ "id": "sec-12-3", "title": "12.3 拓扑登记与每一代连接的重放" },
{ "id": "sec-12-4", "title": "12.4 RunConsumer:全项目唯一的消费循环" },
{ "id": "sec-12-5", "title": "12.5 发布路径:发布 channel 与失败降级" },
{ "id": "sec-12-6", "title": "12.6 死信与重试:声明齐备却从未投递" },
{ "id": "sec-12-7", "title": "12.7 发布可靠性缺口:没有 confirm 的静默丢失" }
]
},
{
"file": "13-chunk.html",
"title": "分片上传:会话、校验与断点续传",
"desc": "讲清 5MB 分片上传的完整设计:Redis 会话模型、四个接口的协作、单片 MD5 校验与按文件指纹秒传、合并落盘与清理,以及并发覆盖的缺口。",
"keywords": "分片上传,断点续传,秒传,MD5,Redis会话,合并",
"level": "L2",
"sections": [
{ "id": "sec-13-1", "title": "13.1 为什么需要分片:限制与网络现实" },
{ "id": "sec-13-2", "title": "13.2 会话模型与两个 Redis 键" },
{ "id": "sec-13-3", "title": "13.3 四个接口的协作流程" },
{ "id": "sec-13-4", "title": "13.4 断点续传与秒传是怎么实现的" },
{ "id": "sec-13-5", "title": "13.5 合并落盘、清理与前端并发池" },
{ "id": "sec-13-6", "title": "13.6 并发覆盖与参数校验缺口" }
]
},
{
"file": "14-notify.html",
"title": "通知、SSE 与私信:实时推送链路",
"desc": "从事件到浏览器:三类通知的落库、用 routing key 充当事件类型的取舍、进程内 SSEHub 的广播与保活、SSE 鉴权,以及私信与前端缺口。",
"keywords": "通知,SSE,实时推送,EventSource,私信,Hub",
"level": "L2",
"sections": [
{ "id": "sec-14-1", "title": "14.1 通知的三种来源与落库" },
{ "id": "sec-14-2", "title": "14.2 用 routing key 充当事件类型的取舍" },
{ "id": "sec-14-3", "title": "14.3 SSEHub:进程内广播与 30 秒保活" },
{ "id": "sec-14-4", "title": "14.4 SSE 鉴权:query token 与 Bearer" },
{ "id": "sec-14-5", "title": "14.5 私信:同步写库与会话查询" },
{ "id": "sec-14-6", "title": "14.6 前端的缺口:通知为什么看不见" }
]
},
{
"file": "15-cache-limit.html",
"title": "缓存与限流:键空间、TTL、分布式锁与窗口算法",
"desc": "把散落在各域的 Redis 用法收拢成一张表:键清单与前缀体系、TTL 分层、分布式锁的正确写法、限流脚本的真实窗口语义与 fail-open 代价。",
"keywords": "缓存,键空间,TTL,分布式锁,限流,滑动窗口",
"level": "L3",
"sections": [
{ "id": "sec-15-1", "title": "15.1 全站 Redis 键清单与前缀体系" },
{ "id": "sec-15-2", "title": "15.2 TTL 分层与失效策略" },
{ "id": "sec-15-3", "title": "15.3 分布式锁:SETNX 加锁与 Lua 释放" },
{ "id": "sec-15-4", "title": "15.4 限流实现:Lua 计数与真实窗口语义" },
{ "id": "sec-15-5", "title": "15.5 限流矩阵与 fail-open 的代价" },
{ "id": "sec-15-6", "title": "15.6 缓存一致性:依赖「顺带失效」的风险" }
]
},
{
"file": "16-observability.html",
"title": "可观测性与部署:探针、pprof、Compose、start.sh 与 CI",
"desc": "交代运维面:两个探针为什么要分开、pprof 入口、三份配置的差异、开发与生产的编排差异、启动脚本的开关顺序,以及指标缺失的空白。",
"keywords": "可观测性,healthz,readyz,pprof,Compose,start.sh,CI",
"level": "L2",
"sections": [
{ "id": "sec-16-1", "title": "16.1 /healthz 与 /readyz:两条通道为什么分开" },
{ "id": "sec-16-2", "title": "16.2 pprof 与本地调试入口" },
{ "id": "sec-16-3", "title": "16.3 三份配置文件的逐项差异" },
{ "id": "sec-16-4", "title": "16.4 Compose:开发与生产的编排差异" },
{ "id": "sec-16-5", "title": "16.5 start.sh:开关、顺序与清理" },
{ "id": "sec-16-6", "title": "16.6 CI 与部署现状" },
{ "id": "sec-16-7", "title": "16.7 可观测性的空白:没有业务指标" }
]
}
]
},
{
"no": "3",
"name": "面试模拟 · 把项目讲出来",
"note": "读懂了不等于讲得出:用题库、讲述模板和深水区问题把理解变成表达。",
"chapters": [
{
"file": "17-interview-core.html",
"title": "高频追问:按模块整理的题库",
"desc": "按八个模块整理的高频追问题库,每题给结论、源码落点与可主动引导的追问方向,用来检验理解是否真的落到代码上。",
"keywords": "面试题,高频追问,题库,项目问答",
"level": "L3",
"sections": [
{ "id": "sec-17-1", "title": "17.1 项目与选型类" },
{ "id": "sec-17-2", "title": "17.2 架构与双进程类" },
{ "id": "sec-17-3", "title": "17.3 鉴权与安全类" },
{ "id": "sec-17-4", "title": "17.4 Feed 与缓存类" },
{ "id": "sec-17-5", "title": "17.5 MQ 与异步一致性类" },
{ "id": "sec-17-6", "title": "17.6 数据库与索引类" },
{ "id": "sec-17-7", "title": "17.7 上传与文件类" },
{ "id": "sec-17-8", "title": "17.8 前端与联调类" }
]
},
{
"file": "18-interview-narrative.html",
"title": "项目讲述:两分钟自述、简历亮点与追问引导",
"desc": "给可直接套用的表达结构:两分钟项目自述模板、三条核心链路的画法、五条可量化的简历亮点,以及主动引导追问的话术与翻车点。",
"keywords": "项目讲述,自我介绍,简历亮点,表达结构",
"level": "L3",
"sections": [
{ "id": "sec-18-1", "title": "18.1 两分钟项目介绍模板" },
{ "id": "sec-18-2", "title": "18.2 三条核心链路的画法" },
{ "id": "sec-18-3", "title": "18.3 五条简历亮点与量化方式" },
{ "id": "sec-18-4", "title": "18.4 主动引导追问的话术" },
{ "id": "sec-18-5", "title": "18.5 讲错就扣分的说法" }
]
},
{
"file": "19-interview-deep.html",
"title": "深水区:并发、幂等、一致性与容量估算",
"desc": "给准备充分的追问准备的深水区:并发与竞态、事件幂等为什么没落地、At-least-once 与对账、缓存治理,以及容量估算与演进方向。",
"keywords": "深水区,并发,幂等,一致性,对账,容量估算,演进",
"level": "L3",
"sections": [
{ "id": "sec-19-1", "title": "19.1 并发与竞态:状态机、锁与原子更新" },
{ "id": "sec-19-2", "title": "19.2 幂等:event_id 为什么存在却没被用上" },
{ "id": "sec-19-3", "title": "19.3 一致性:At-least-once、重复写与对账" },
{ "id": "sec-19-4", "title": "19.4 缓存治理:穿透、击穿、雪崩与陈旧窗口" },
{ "id": "sec-19-5", "title": "19.5 容量估算与瓶颈定位" },
{ "id": "sec-19-6", "title": "19.6 演进方向:从单实例到可水平扩展" }
]
}
]
},
{
"no": "4",
"name": "场景还原 · 端到端与故障",
"note": "把前面读到的碎片串成链路,再逐个制造故障看系统怎么表现。",
"chapters": [
{
"file": "20-scenarios-e2e.html",
"title": "三条核心链路端到端还原",
"desc": "把发布一条视频、点赞一次、刷一次 Feed 三条链路从头到尾串起来,标出每一步经过的表、键、队列与文件,并给出可复现的验证方式。",
"keywords": "端到端,链路还原,发布,点赞,刷Feed,验证",
"level": "L3",
"sections": [
{ "id": "sec-20-1", "title": "20.1 链路一:发布一条视频并进入推荐流" },
{ "id": "sec-20-2", "title": "20.2 链路二:点赞一次直到热度生效" },
{ "id": "sec-20-3", "title": "20.3 链路三:刷一次 Feed 的完整决策" },
{ "id": "sec-20-4", "title": "20.4 三条链路涉及的表、键、队列与文件" },
{ "id": "sec-20-5", "title": "20.5 怎么验证链路真的走通了" }
]
},
{
"file": "21-scenarios-failure.html",
"title": "故障场景:MQ 断连、Redis 失效、DB 抖动与消息重复",
"desc": "逐个制造故障:RabbitMQ 重启与拓扑丢失、Redis 不可用、MySQL 抖动导致消息处理失败、消息重复与双写、通知失效,并给出每个场景的止血清单。",
"keywords": "故障场景,降级,断连,幂等,重复消费,止血",
"level": "L3",
"sections": [
{ "id": "sec-21-1", "title": "21.1 RabbitMQ 整体重启" },
{ "id": "sec-21-2", "title": "21.2 队列被删、拓扑丢失" },
{ "id": "sec-21-3", "title": "21.3 Redis 不可用" },
{ "id": "sec-21-4", "title": "21.4 MySQL 抖动与消息处理失败" },
{ "id": "sec-21-5", "title": "21.5 消息重复与 MQ 假失败导致的双写" },
{ "id": "sec-21-6", "title": "21.6 通知与实时推送失效" },
{ "id": "sec-21-7", "title": "21.7 每个场景的止血与恢复清单" }
]
}
]
},
{
"no": "5",
"name": "收尾 · 速查与自测",
"note": "所有需要背下来的常量级事实集中在这里,配一份自测清单。",
"chapters": [
{
"file": "22-cheatsheet.html",
"title": "速查表与自测清单",
"desc": "把接口、表与索引、Redis 键与 TTL、MQ 拓扑、配置项这些常量级事实集中成速查表,并给出一份可以逐条打勾的能力自测清单。",
"keywords": "速查表,接口清单,Redis键,MQ拓扑,自测清单",
"level": "L4",
"sections": [
{ "id": "sec-22-1", "title": "22.1 接口速查:全量路由一览" },
{ "id": "sec-22-2", "title": "22.2 数据表与索引速查" },
{ "id": "sec-22-3", "title": "22.3 Redis 键与 TTL 速查" },
{ "id": "sec-22-4", "title": "22.4 MQ 拓扑与路由键速查" },
{ "id": "sec-22-5", "title": "22.5 配置与环境变量速查" },
{ "id": "sec-22-6", "title": "22.6 能力自测清单与继续深入" }
]
}
]
}
]
}