24 June 2026, 18:00 (CST)
2026年06月24日 10:11(东八区 / 北京时间)
GitHub Pages 部署流水线 ENAMETOOLONG · 看板 Markdown 误为 symlink
概述
SuchaharCan.github.io Actions #28 在 Init 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 CI | Git 检出为 symlink | stat 跟随链接 → 目标为整段 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 ← 正常文件- Git mode
120000= symlink;blob 内本应只存 目标路径字符串 - 实际 blob 大小 2526 字节,内容为
+++开头的完整周计划 Markdown - Linux
git clone按 symlink 检出 → 链接目标 = 整篇文档文本 →statSync/readlink解析时触发ENAMETOOLONG
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.md | git rm --cached 后重新 git add,索引 mode 100644(普通文件) |
scripts/encrypt-content.mjs | walkMd 用 readdirSync({ withFileTypes: true }),跳过 symlink;ROOT 改用 fileURLToPath |
build-site.sh | 解析 --output-dir,export ZOLA_OUTPUT_DIR 供后续 Node 脚本 |
scripts/patch-search-index.mjs | 读取 ZOLA_OUTPUT_DIR 定位搜索索引;输出目录不存在时安全退出 |
scripts/verify-kanban-build.mjs | fileURLToPath 统一 ROOT |
.github/workflows/deploy_pages.yml | 验证步骤改为 [ -d "../public_html" ] |
加固后的 walkMd 逻辑(即使将来再误入 symlink 也不会拖垮构建):
forconst ent of readdirSyncdir, {: true } {
ifent.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.yml 中 Verify Kanban build output 的路径修正同步到该仓库(../public_html)。
4.3 重跑流水线
GitHub → Actions → Build Zola and Deploy to GitHub Pages → Run workflow
期望日志顺序:
encryption: N page(s) → static/encryption/pages/(无 ENAMETOOLONG)zola build→Done in …mskanban verify OK: 2 week(s), list cards match✅ 验证通过:public_html … index.html- 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. 经验小结
ENAMETOOLONG+ 路径看起来不长 → 优先查 symlink 目标 与git ls-files -smode,不要只看路径字符串长度。- 跨平台构建 → 加密/遍历类脚本应 不跟随 symlink,并用
fileURLToPath解析 ESM 路径。 build-site.sh包装多步 →--output-dir须 显式传播 给所有读public/的后置脚本。- CI 与本地目录布局不同 → workflow 验证路径要与
zola build --output-dir同一基准(本次为zola_source的上一级public_html)。
相关链接:deploy workflow · 失败 Run #28 · 看板列表 · 前一篇 Nanolog(看板 UI / 热力图)
24 June 2026, 12:00 (CST)