Skip to content

Commit

Permalink
update utils, add filters, data
Browse files Browse the repository at this point in the history
  • Loading branch information
ereminnf committed Aug 26, 2020
1 parent 107945a commit 64bfb14
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,27 @@ module.exports = function(content) {
this.cacheable();

const callback = this.async();
const opt = utils.getOptions(this.query);
const opt = utils.getOptions(this);

const nunjucksSearchPaths = opt.searchPaths;
const nunjucksContext = opt.context;
// options
const paths = opt.paths;
const data = opt.data;
const filters = opt.filters;

const loader = new NunjucksLoader(nunjucksSearchPaths, function(path) {
const loader = new NunjucksLoader(paths, function(path) {
this.addDependency(path);
}.bind(this));

const nunjEnv = new nunjucks.Environment(loader);
nunjucks.configure(null, { watch: false });

const template = nunjucks.compile(content, nunjEnv);
const html = template.render(nunjucksContext);
const env = new nunjucks.Environment(loader);
nunjucks.configure(null, { watch: false });

// filters
for (const key in filters) {
env.addFilter(key, filters[key]);
}

const template = nunjucks.compile(content, env);
const html = template.render(data);

callback(null, html);
};

0 comments on commit 64bfb14

Please sign in to comment.