Skip to Main Content
404Back to Top
24 June 2026, 22:00 (CST)

24 June 2026, 18:00 (CST)

2026年06月24日 10:11(东八区 / 北京时间)

概述

SuchaharCan.github.io Actions #28Init theme submodule and build 阶段失败:encrypt-content.mjs 遍历 content/ 时对 content/kanban/2026-06-16.md 调用 statSync 抛出 ENAMETOOLONG。本地 macOS 复现困难,Linux CI 必现。

根因:该文件在 Git 索引中被误记为 symlink(mode 120000),但 blob 内容是整篇 Markdown;Linux 检出后符号链接目标 ≈ 2500 字符的「伪路径」,stat 解析失败。附带修复了 build-site.sh 与 CI 验证路径问题。


1. 现象

1.1 CI 报错摘要

Error: ENAMETOOLONG: name too long, stat
  '.../zola_source/content/kanban/2026-06-16.md'
    at walkMd (scripts/encrypt-content.mjs:52)
    at main (scripts/encrypt-content.mjs:81)

流水线:deploy_pages.yml — Codeberg 拉源码 → ./build-site.sh --output-dir ../public_html → 首步即 node scripts/encrypt-content.mjs

1.2 为何本地未报错

环境2026-06-16.md 磁盘形态encrypt-content.mjs 行为
本地 macOS普通文件 -rw-r--r--stat 正常
Linux CIGit 检出为 symlinkstat 跟随链接 → 目标为整段 Markdown → ENAMETOOLONG

表面看报错路径长度正常(约 100 字符),容易误判为路径拼接 bug;需结合 Git 对象 mode 才能定位。


2. 根因定位(思考链)

2.1 排除项

假设结论
import.meta.url.pathname 在 Linux 上算错 ROOT可能改进,但无法解释仅 单个 kanban 文件 失败
content/kanban/ 存在目录级 symlink 循环本地 find -type l 无异常;问题在 单文件 mode
kanban 需加密导致读文件失败kanban 未开 [extra.encryption];失败发生在 walk 阶段,尚未读内容

2.2 关键命令

git ls-files -s content/kanban/
# 120000 71584b78...  content/kanban/2026-06-16.md   ← symlink mode
# 100644 18e34c47...  content/kanban/2026-06-22.md   ← 正常文件

2.3 成因推测

某次提交或合并时,该文件被错误标记为 symlink(可能来自错误 git add、工具导入或复制粘贴异常),而 blob 仍写入 Markdown 正文。macOS 工作区可能曾被手动覆盖为普通文件,故与 CI 表现不一致。

2.4 附带问题(修复 CI 全流程时发现)

问题说明
build-site.sh 未导出 ZOLA_OUTPUT_DIR./build-site.sh --output-dir ../public_html 时,patch-search-index.mjs / verify-kanban-build.mjs 仍读 public/
workflow 验证路径错误构建输出在 ../public_html,步骤却检查 zola_source/public_html

3. 修复内容

文件改动
content/kanban/2026-06-16.mdgit rm --cached 后重新 git add,索引 mode 100644(普通文件)
scripts/encrypt-content.mjswalkMdreaddirSync({ withFileTypes: true })跳过 symlinkROOT 改用 fileURLToPath
build-site.sh解析 --output-direxport ZOLA_OUTPUT_DIR 供后续 Node 脚本
scripts/patch-search-index.mjs读取 ZOLA_OUTPUT_DIR 定位搜索索引;输出目录不存在时安全退出
scripts/verify-kanban-build.mjsfileURLToPath 统一 ROOT
.github/workflows/deploy_pages.yml验证步骤改为 [ -d "../public_html" ]

加固后的 walkMd 逻辑(即使将来再误入 symlink 也不会拖垮构建):

for (const ent of readdirSync(dir, { withFileTypes: true })) {
  if (ent.isSymbolicLink()) continue;
  // ...
}

4. 解决步骤

部署架构:Codeberg 私有源码 + GitHub.io 仅托管 workflow 与 gh-pages 静态页

4.1 推送 Codeberg(必须)

仓库:codeberg.org/SuzhaharCan/SuzhaharCan.codeberg.page

git add content/kanban/2026-06-16.md \
        scripts/encrypt-content.mjs \
        scripts/patch-search-index.mjs \
        scripts/verify-kanban-build.mjs \
        build-site.sh
git commit -m "fix: kanban week file git mode and CI build output paths"
git push origin main   # 或当前默认分支

4.2 同步 GitHub.io workflow(若与 Codeberg 副本不一致)

仓库:SuchaharCan/SuchaharCan.github.io

deploy_pages.ymlVerify Kanban build output 的路径修正同步到该仓库(../public_html)。

4.3 重跑流水线

GitHub → ActionsBuild Zola and Deploy to GitHub PagesRun workflow

期望日志顺序:

  1. encryption: N page(s) → static/encryption/pages/(无 ENAMETOOLONG)
  2. zola buildDone in …ms
  3. kanban verify OK: 2 week(s), list cards match
  4. ✅ 验证通过:public_html … index.html
  5. Deploy push 至 gh-pages

4.4 线上验收

检查项期望
/kanban/2 张周卡片
/kanban/2026-06-16/200,非 404
构建日志encrypt-content.mjs 栈追踪

5. 本地验证

# 模拟 CI 自定义输出目录
ZOLA_OUTPUT_DIR=public_test ./build-site.sh --output-dir public_test
# 期望:kanban verify OK: 2 week(s), list cards match

# 确认 Git 索引 mode
git ls-files -s content/kanban/2026-06-16.md
# 期望:100644 ...

6. 经验小结

  1. ENAMETOOLONG + 路径看起来不长 → 优先查 symlink 目标git ls-files -s mode,不要只看路径字符串长度。
  2. 跨平台构建 → 加密/遍历类脚本应 不跟随 symlink,并用 fileURLToPath 解析 ESM 路径。
  3. build-site.sh 包装多步--output-dir显式传播 给所有读 public/ 的后置脚本。
  4. CI 与本地目录布局不同 → workflow 验证路径要与 zola build --output-dir 同一基准(本次为 zola_source 的上一级 public_html)。

相关链接:deploy workflow · 失败 Run #28 · 看板列表 · 前一篇 Nanolog(看板 UI / 热力图)

24 June 2026, 12:00 (CST)