From 55608ae2d747c34218119ee1d74a040e576da3ce Mon Sep 17 00:00:00 2001 From: Laza Bogdan Date: Wed, 12 Apr 2017 13:06:47 +0300 Subject: [PATCH] add support for front-matter - https://www.npmjs.com/package/front-matter (assigns context from YAML metadata) --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index 1627fcb..1fee74b 100644 --- a/index.js +++ b/index.js @@ -63,6 +63,13 @@ module.exports = function(content) { var nunjEnv = new nunjucks.Environment(loader); nunjucks.configure(null, { watch: false }); + + try { + var frontmatter = JSON.parse(content) + content = frontmatter.body + nunjucksContext = Object.assign({}, nunjucksContext, frontmatter.attributes) + } + catch(e) {} var template = nunjucks.compile(content, nunjEnv); html = template.render(nunjucksContext);