Skip to Main Content
404Back to Top

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

本轮重构目标:tagsgenerate_feedsscripts 一样——在文章 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 + RSSsearch_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.mjs

CI(.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 在构建完成后:

  1. 遍历 public/**/index.html,识别含 article-encrypted 的页面 URL;
  2. 递归扫描所有 atom.xml / rss.xml
  3. 删除链接到上述 URL 的 <entry>(Atom)与 <item>(RSS)块。

已验证:02Engineer_blog_Debug 分区 feed 中,deny-website-littlesnitchchrome-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 Chaterstatic/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 为准;下次构建会全量刷新。

24 June 2026, 22:00 (CST)