Nunjucks is a full featured templating engine for javascript. It is heavily inspired by jinja2. View the docs here.
由于nunjucks
模板引擎不兼容emberjs的{{}}
标签,所以修改了nunjucks
模板引擎的标签占位符。
nunjucks默认占位符 | 修改后的占位符 |
---|---|
{{ |
{$ |
}} |
$} |
{# |
{@ |
#} |
@} |
修改后使用nunjucks
模板引擎解析的hexo插件会解析失败,所以需要同步修改依赖nunjucks
模板引擎的hexo插件。
另外有一点很重要,如果你的其他hexo查询有依赖这个模板引擎,还必须要修改插件中的解析占位符。否则你安装的hexo查询将无效,比如xcoding中的搜索和RSS插件就是依赖这个模板引擎。所以需要修改他们的解析代码中的占位符。 如果你不想修改可以直接使用我已经修改好的插件。
已经修改过的插件:
之所以这么做是因为hexo使用nunjucks
解析生成静态HTML。然后我的主站xcoding使用了GitHub+hexo搭建。然后博客主要用于记录EmberJS相关文章,EmberJS很多标签都是使用{{}}
,与模板引擎的占位符冲突。
冲突出现的问题如下:
http://hexo.io/docs/troubleshooting.html
Template render error: (unknown path) [Line 37, Column 81]
expected variable end
Unhandled rejection Template render error: (unknown path) [Line 10, Column 95]
unexpected token: #
当然也有其他解决方案,但是自定义模板占位符是比较好的方法,详细可以看如下博客: 如何从根本解决hexo不兼容{{}}标签问题
npm install nunjucks-cst
(View the CHANGELOG)
See here.
Supported in all modern browsers. For IE8 support, use es5-shim.
Run the tests with npm test
.
Watch master
branch's tests running in the browser.
Join our mailing list and get help with and issues you have: https://groups.google.com/forum/?fromgroups#!forum/nunjucks
Contributions are always welcome! Before you submit an issue or pull request, please read our contribution guidelines.