我在玩hexo,我正在测试nunjuck语法,它适用于一个小循环。然而,我无法找到如何包括一个文件,我的文件的位置(目前在.md旁边,在/source/_posts中)可能是错误的。
环境信息
节点版本(node -v):
node --version; npm --version
v8.9.1
5.5.1您的站点_config.yml (可选):
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: Hexo
subtitle:
description:
author: John Doe
language:
timezone:
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:
# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: false
tab_replace:
# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -date
# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
# Pagination
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type:
</details>Hexo和插件版本(npm ls --depth 0):
"hexo": "^3.2.0",
"hexo-generator-archive": "^0.1.4",
"hexo-generator-category": "^0.1.3",
"hexo-generator-index": "^0.2.0",
"hexo-generator-tag": "^0.2.0",
"hexo-renderer-ejs": "^0.3.0",
"hexo-renderer-stylus": "^0.3.1",
"hexo-renderer-marked": "^0.3.0",
"hexo-server": "^0.2.0"目录结构
tree ./
./
├── include
│ └── colors.html
└── _posts
└── button6.md用法
npm install --save --only=prod hexo-include我在纽扣上添加了
{% include "include/colors.html" %}错误
Unhandled rejection Template render error: (unknown path)
Error: template not found: include/colors.html有疑问
我有这个帖子在_hexo-演示/源代码/ post /按钮6.md
---
title: button6
myitems:
- one
- two
---
{% for item in myitems %}
<li> {{ item }}</li>
{% endfor %}
<hr>
{% include "colors.html" %}问题
我应该把我的colors.html文件放在哪里才能被解析
发布于 2019-05-08 01:36:31
我也有同样的问题。看来hexo-包括与numjack的冲突。我在下面更改lib/index.js
hexo.extend.tag.register('include_alt', include, {asyn: true});但还是没用的。这可能是因为渲染时间。因此,我修改了lib/index.js
var fs = require('hexo-fs');
var nunjucks = require('nunjucks');
var pathFn = require('path');
// hexo.extend.tag.register('include_alt', include, { asyn: true });
hexo.extend.tag.register('include_alt', function (args) {
var path = pathFn.join(hexo.source_dir, args[0]);
return new Promise(function(resolve, reject) {
nunjucks.render(path, function(err, res) {
if (err) {
return reject(err);
}
resolve(res);
});
});
}, {async: true});然后我用它作为
{% include_alt 'some.html' %}而且起作用了。
发布于 2017-11-22 07:37:25
在hexo中没有本地支持。标签受章鱼启发,据我所知,八达通的部分标签并不存在于hexo中。
好消息是这里有一个hexo插件:
https://github.com/PirtleShell/hexo-include
一旦安装,您可以简单地
{% include colors.html %}colors.html在source文件夹根目录的位置
https://stackoverflow.com/questions/47419747
复制相似问题