-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderView.js
More file actions
26 lines (24 loc) · 794 Bytes
/
renderView.js
File metadata and controls
26 lines (24 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var fs = require("fs");
var path = require("path");
var frontmatter = require("frontmatter");
var mustache = require("mustache");
function renderView(view, viewModel, callback) {
if(!callback) {
callback = viewModel;
viewModel = {};
}
view = mustache.render(view, viewModel);
var page = frontmatter(view);
if(!page.data || !page.data.layout) {
return callback(null, view);
}
var layoutPath = path.join(__dirname, "layouts", page.data.layout + ".html");
fs.readFile(layoutPath, function(error, layoutBuf) {
if(error) {
return callback(error);
}
var merged = mustache.render(layoutBuf.toString(), { content: page.content });
renderView(merged, callback);
});
}
module.exports = renderView;