一 现象描述
最近写了一篇文章,在执行hexo g指令时生成文章预览时,会发生错误,错误信息如下:
1 2 3 4 | Unhandled rejection Nunjucks Error: _posts/xxxxxxxxxxx.md [Line 27, Column 114] unexpected token: }}
===== Context Dump =====
=== (line number probably different from source) ===
22 | <!--code3-->
|

二 原因分析
2.1 分析过程
- 将本篇文章删除后,hexo g 能正常执行,说明是本篇文章引起的问题
- 将本篇文章的内容删除后,hexo指令能正常执行,说明不是头部categories和tags引起的问题
- 确定是文章内容引起的问题,根据错误信息,逐步缩小查找范围,最终确定是"{{"引起的错误
2.3 原因搜索
- 复制错误信息
Unhandled rejection Nunjucks Error搜索 - 确定上步"{{"引起的hexo指令错误进行搜索
- 根据错误信息给出的地址https://hexo.io/docs/troubleshooting.html
2.4 原因解释(hexo troubleshooting)
1 2 3 4 5 6 7 8 9 10 | Escape Contents
Hexo uses Nunjucks to render posts (Swig was used in older version, which share a similar syntax). Content wrapped with {{ }} or {% %} will get parsed and may cause problems. You can skip the parsing by wrapping it with the raw tag plugin, single backtick `{{ }}` or triple backtick.
Alternatively, Nunjucks tags can be disabled through the renderer’s option (if supported), API or front-matter.
{% raw %}
Hello {{ world }}
{% endraw %}
```
Hello {{ world }}
```
|
三 解决办法
-
修改前
1
"{{}}" -
修改后
1
{% raw %}"{{}}"{% endraw %}
1725

被折叠的 条评论
为什么被折叠?



