I am working on setting up a workflow for generating static pages using Markdown and Nunjucks, through Gulp. The current two tasks I rely on for this are:
gulp.task('templates', function() {
return gulp.src('app/templates/pages/*.nunjucks')
.pipe(nunjucksRender({
path: ['app/templates/', 'app/templates/pages/']
}))
.pipe(gulp.dest('app'));
});
gulp.task('pages', function() {
gulp.src('app/pages/**/*.md')
.pipe(frontMatter())
.pipe(marked())
.pipe(wrap(function (data) {
return fs.readFileSync('app/templates/pages/' + data.file.frontMatter.layout).toString()
}, null, {engine: 'nunjucks'}))
.pipe(gulp.dest('app'))
});
With the following structure:
/app
| index.html
|
+---css
| app.scss
| custom.scss
|
+---js
| app.js
|
+---pages
| index.md
|
\---templates
| layout.nunjucks
|
+---macros
| nav-macro.nunjucks
|
+---pages
| index.nunjucks
|
\---partials
navigation.nunjucks
If I run gulp templates
this compiles index.html into /app using index.nunjucks which extends layout.nunjucks. However, I want to use gulp pages
to draw frontmatter and Markdown from index.md to generate the contents of index.html.
The problem I am having is pathing: Given the structure above, how to I use /app/pages/index.md as the content for /app/index.html through /app/templates/pages/index.nunjucks? Currently the task fails with Template render error: (unknown path)
.
Essentially, I am trying to extend what is achieved here: Gulp Front Matter +Markdown through Nunjucks