Skip to content

Commit

Permalink
Merge 1e85e39 into c8d47b8
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Parisot committed Dec 13, 2017
2 parents c8d47b8 + 1e85e39 commit 184f0c6
Show file tree
Hide file tree
Showing 6 changed files with 4,606 additions and 53 deletions.
3 changes: 2 additions & 1 deletion lib/plugins/renderer/index.js
Expand Up @@ -12,7 +12,8 @@ module.exports = function(ctx) {

renderer.register('json', 'json', require('./json'), true);

renderer.register('swig', 'html', require('./swig'), true);
renderer.register('swig', 'html', require('./nunjucks'), true);
renderer.register('njk', 'html', require('./nunjucks'), true);

var yaml = require('./yaml');

Expand Down
33 changes: 33 additions & 0 deletions lib/plugins/renderer/nunjucks.js
@@ -0,0 +1,33 @@
'use strict';

var nunjucks = require('nunjucks');
var fs = require('hexo-fs');

nunjucks.configure('views', {
noCache: true,
autoescape: false,
// throwOnUndefined: true
});

function nunjucksRenderer(data, locals) {
if ('text' in data) {
return nunjucks.renderString(data.text, locals);
}

return nunjucks.render(data.path, locals);
}

nunjucksRenderer.compile = function(data) {
var compiled;

if ('text' in data) {
compiled = nunjucks.compile(data.text);
}
else {
compiled = nunjucks.compile(fs.readFileSync(data.path));
}

return compiled.render.bind(compiled);
};

module.exports = nunjucksRenderer;
47 changes: 0 additions & 47 deletions lib/plugins/renderer/swig.js

This file was deleted.

0 comments on commit 184f0c6

Please sign in to comment.