-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetalsmith-layout.js
44 lines (38 loc) · 1.46 KB
/
metalsmith-layout.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var hogan = require('hogan.js');
var fs = require('fs');
var async = require('async');
module.exports = function () {
return function layout (files, metalsmith, callback) {
async.auto({
layout: function (callback) {
fs.readFile(__dirname + '/templates/layout.html', callback);
},
article: function (callback) {
fs.readFile(__dirname + '/templates/article.html', callback);
}
}, function (err, obj) {
var layout = hogan.compile(obj.layout.toString());
var article = hogan.compile(obj.article.toString());
for (var file in files) {
if (
file.indexOf('.md') === -1 &&
file.indexOf('.html') === -1
) continue;
var doc = files[file];
var content = '';
if (doc.collection
&& (doc.collection.indexOf('articles') > -1 || doc.collection.indexOf('projects') > -1)) {
content = article.render({ article: doc.contents });
} else {
content = doc.contents
}
doc.contents = layout.render({
title: doc.title || metalsmith._metadata.global.title,
content: content,
global: metalsmith._metadata.global
});
};
callback();
});
};
};