┌──────────────────────────────────────────────────────────────┐
│ 第一步:制造错误 (2 min) │
│ ─────────────────────────────────────────────────────────── │
│ $ vim _layouts/ec440.html │
│ 找到最后一行的 {\% endif \%} │
│ ❌ 改成: {\% comment \%} missing {\% endcomment \%} │
│ 保存: :wq │
└──────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────┐
│ 第二步:观察错误 (2 min) │
│ ─────────────────────────────────────────────────────────── │
│ $ bundle exec jekyll serve │
│ 看到: ❌ Liquid Exception: ... 'endif' expected │
│ 按 Ctrl+C 停止 │
└──────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────┐
│ 第三步:诊断问题 (3 min) │
│ ─────────────────────────────────────────────────────────── │
│ $ bundle exec jekyll build --trace │
│ 查看输出中的三个关键信息: │
│ 1️⃣ 错误类型: Liquid Exception │
│ 2️⃣ 文件位置: _layouts/ec440.html, line 42 │
│ 3️⃣ 问题描述: Expected 'endif' │
└──────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────┐
│ 第四步:查看代码上下文 (2 min) │
│ ─────────────────────────────────────────────────────────── │
│ $ sed -n '38,45p' _layouts/ec440.html │
│ 输出: │
│ 38 {\% if page.toc \%} │
│ 39 <div> │
│ 40 ... │
│ 41 </div> │
│ 42 {\% comment \%} ERROR HERE {\% endcomment \%} ❌ │
│ 43 │
│ 44 <footer> │
└──────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────┐
│ 第五步:修复错误 (2 min) │
│ ─────────────────────────────────────────────────────────── │
│ $ vim _layouts/ec440.html │
│ 改回: {\% endif \%} │
│ 保存: :wq │
└──────────────────────────────────────────────────────────────┘
┌──────────────────────────────────────────────────────────────┐
│ 第六步:验证修复 (2 min) │
│ ─────────────────────────────────────────────────────────── │
│ $ bundle exec jekyll build │
│ 看到: ✅ ... done in 2.345 seconds │
│ 没有错误 = 成功! │
│ 访问 http://localhost:4000 确认网站正常 │
└──────────────────────────────────────────────────────────────┘
原因: Liquid 模板标签未闭合或拼写错误
检查: ✓ {\% if \%} 对应 {\% endif \%} 吗?
✓ {\% for \%} 对应 {\% endfor \%} 吗?
✓ 过滤器名称对吗?
修复: vim [文件] +[行号]
原因: YAML 格式错误(缺引号、缩进、特殊字符)
检查: ✓ 引号成对了吗? ("..." 或 '...')
✓ 缩进统一了吗? (都用 2 个空格)
✓ 有特殊字符吗? (冒号、#...需要加引号)
修复: vim _config.yml
原因: 缺少或冲突的 Ruby 包
检查: ✓ bundle check
✓ bundle install
修复: bundle install && bundle update
原因: 配置中的路径不存在
检查: ✓ ls -la [路径]
✓ _config.yml 中什么路径出错了?
修复: 修改配置或创建目录
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ 永远首先查看日志,日志里有所有答案! ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
诊断错误的 4 步:
1️⃣ 获取完整日志信息
2️⃣ 定位文件和行号
3️⃣ 查看代码上下文
4️⃣ 对比之前的版本
修复问题的 3 步:
1️⃣ 理解问题原因
2️⃣ 做出改动
3️⃣ 验证修复有效