Skip to content

Commit

Permalink
fix(nunjucks): add template path to env
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jun 28, 2020
1 parent 026c197 commit fe37aca
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/plugins/renderer/nunjucks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

const nunjucks = require('nunjucks');
const fs = require('hexo-fs');
const { dirname } = require('path');

function toArray(value) {
if (Array.isArray(value)) {
Expand Down Expand Up @@ -31,16 +32,16 @@ function safeJsonStringify(json, spacer = undefined) {
return '""';
}

const env = nunjucks.configure({
autoescape: false,
throwOnUndefined: false,
trimBlocks: false,
lstripBlocks: false
});
env.addFilter('toArray', toArray);
env.addFilter('safeDump', safeJsonStringify);

function njkCompile(data) {
const env = nunjucks.configure(dirname(data.path), {
autoescape: false,
throwOnUndefined: false,
trimBlocks: false,
lstripBlocks: false
});
env.addFilter('toArray', toArray);
env.addFilter('safeDump', safeJsonStringify);

return nunjucks.compile(
'text' in data ? data.text : fs.readFileSync(data.path),
env,
Expand Down

0 comments on commit fe37aca

Please sign in to comment.