25 June 2026, 04:00 (CST)
2026年06月24日 20:00(东八区 / 北京时间)
文章加密模块重构 · 全量同步 · RSS/Atom 过滤
概述
加密功能原先与 Zola 构建耦合过紧:模板在 zola build 阶段用 load_data() 读取 static/encryption/pages/*.json,若密文尚未生成(例如首次给文章加上 encrypt = true 后直接跑 zola build),会报错 Could not find or open file encryption/pages/....json。
本轮重构目标:像 tags、generate_feeds、scripts 一样——在文章 front matter 里声明即可;构建脚本负责全量同步密文;订阅源与搜索索引自动排除加密正文。
1. 新架构
content/**/*.md
[extra.encryption] encrypt = true
↓
① scripts/encrypt-content.mjs 全量扫描 → 全量重加密 → 删除多余 JSON
↓
② zola build 模板不再 load_data,运行时 fetch 密文
↓
③ scripts/post-build.mjs 从 RSS/Atom + 搜索索引剔除加密文章
↓
public/ 静态站点| 阶段 | 脚本 | 职责 |
|---|---|---|
| 构建前 | encrypt-content.mjs | 扫描 content/,对所有 encrypt = true 的文章重新加密(不论是否改过正文);取消加密的文章对应 JSON 从 static/encryption/pages/ 删除 |
| 构建 | zola build | 加密页渲染锁屏 UI;正文由浏览器 article.js 按管理员/访客规则 fetch 解密 |
| 构建后 | post-build.mjs | 扫描 public/ 中含 article-encrypted 的页面,从 Atom + RSS 及 search_index 中移除对应条目 |
共享逻辑集中在 scripts/encryption-lib.mjs(扫描、路径映射、feed/XML 过滤)。
2. 使用方式
2.1 启用加密(任意文章)
在 front matter 增加:
[extra.encryption]
encrypt = true无需预先创建 JSON 文件,也无需改模板。
2.2 生产构建
./build-site.sh
# 等价于:
# node scripts/encrypt-content.mjs
# zola build
# node scripts/post-build.mjs
# node scripts/verify-kanban-build.mjsCI(.github/workflows/deploy_pages.yml)同样调用 ./build-site.sh --output-dir ../public_html。
2.3 本地开发
| 场景 | 命令 | 说明 |
|---|---|---|
| 新增或修改加密文章 | ./dev.sh | 先跑 encrypt-content.mjs 生成/更新密文,再 zola serve |
| 无加密相关改动 | zola build / zola serve | 足够;密文已在 static/encryption/pages/ 中,无需重复加密 |
要点:只有当你新增加密文章、或改了某篇加密文章的正文/front matter 时,本地需先执行
./dev.sh(或单独node scripts/encrypt-content.mjs)。若本次会话没有动过加密配置,日常改样式/改非加密文章,直接zola serve即可。
./dev.sh 源码:
node scripts/encrypt-content.mjs
exec zola serve "$@"3. 主要改动
| 文件 | 改动 |
|---|---|
scripts/encryption-lib.mjs | 共享:扫描 encrypt=true、全量 sync、收集加密 URL、strip feed/search |
scripts/encrypt-content.mjs | 每次构建清空 pages/ 后重建;更新 manifest.json |
scripts/post-build.mjs | 新增:构建后过滤 RSS/Atom 与搜索索引 |
scripts/patch-search-index.mjs | 弃用,转发至 post-build.mjs |
templates/partials/encrypted_article.html | 移除 load_data(),仅保留 data-payload-url 运行时加载 |
build-site.sh | 接入 post-build.mjs;修复无参数时 ZOLA_ARGS 未绑定 |
dev.sh | 新增:本地开发入口(加密同步 + serve) |
4. RSS / Atom 过滤加密内容
问题:Zola 生成订阅源时直接序列化 Markdown 正文,加密文章虽在 HTML 页显示锁屏,但 Atom/RSS 仍会泄露全文。
处理:post-build.mjs 在构建完成后:
- 遍历
public/**/index.html,识别含article-encrypted的页面 URL; - 递归扫描所有
atom.xml/rss.xml; - 删除链接到上述 URL 的
<entry>(Atom)与<item>(RSS)块。
已验证:02Engineer_blog_Debug 分区 feed 中,deny-website-littlesnitch、chrome-reopen 等加密条目构建后不再出现。
搜索索引沿用同一 URL 列表,由 post-build.mjs 一并 patch(原 patch-search-index.mjs 逻辑合并)。
5. 触发案例
02Engineer_blog_Debug/2026-06-20-Deny-WebSite-LittleSnitch 首次添加 [extra.encryption] encrypt = true 后直接 zola build,曾报:
Could not find or open file encryption/pages/02Engineer_blog_Debug/2026-06-20-Deny-WebSite-LittleSnitch.json重构后:运行 ./dev.sh 或 ./build-site.sh 即可自动生成密文;单独 zola build 不再因 load_data 失败,但新增加密页时仍需先同步密文(见 §2.3)。
6. 当前已加密文章(构建快照)
| 文章 | 密文路径 |
|---|---|
00Read_blog_Math/2026-06-03-First Base Chater | static/encryption/pages/00Read_blog_Math/2026-06-03-First Base Chater.json |
02Engineer_blog_Debug/2026-06-20-Deny-WebSite-LittleSnitch | .../2026-06-20-Deny-WebSite-LittleSnitch.json |
02Engineer_blog_Debug/2026-06-23-Chrome-ReOpen | .../2026-06-23-Chrome-ReOpen.json |
清单以 static/encryption/manifest.json 为准;下次构建会全量刷新。