Skip to content

Commit b856dc0

Browse files
authored
Merge pull request #140 from theme-next/feature-include-raw
Added `include_raw` tag feature.
2 parents 9c0859b + 92a7afc commit b856dc0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

scripts/tags/include-raw.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* include.js | global hexo script.
3+
*
4+
* Usage:
5+
*
6+
* {% include_raw '_data/path/to/file.html' %}
7+
*
8+
* Path is relative to your site source directory.
9+
*/
10+
11+
'use strict';
12+
13+
var pathFn = require('path');
14+
/*jshint camelcase: false */
15+
var fs = require('hexo-fs');
16+
/*jshint camelcase: true */
17+
18+
function include_raw (args) {
19+
var path = pathFn.join(hexo.source_dir, args[0]);
20+
21+
return fs.exists(path).then(function(exist) {
22+
if (!exist) {
23+
hexo.log.error('Include file not found!');
24+
return;
25+
}
26+
return fs.readFile(path).then(function(contents) {
27+
if (!contents) {
28+
hexo.log.warn('Include file empty.');
29+
return;
30+
}
31+
return contents;
32+
});
33+
});
34+
};
35+
36+
hexo.extend.tag.register('include_raw', include_raw, {ends: false, async: true});

0 commit comments

Comments
 (0)