-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
49 lines (38 loc) · 1.13 KB
/
index.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
45
46
47
48
49
/**
* metasmith-hbt-md
* Process Handlebars in Markdown files
*
* @author Antonio Hernandez <[email protected]>
* @license MIT
*/
const match = require('multimatch'),
debug = require('debug')('metalsmith-hbt-md');
/**
* Process Handlebars in Markdown files
*/
const plugin = function (handlebars, options) {
options = options || {
pattern: '**/*.md'
};
return function (files, metalsmith, done) {
setImmediate(done);
const meta = metalsmith.metadata();
Object.keys(files).forEach(function (key) {
if (match(key, options.pattern).length === 0) {
return;
}
debug('Processing ' + key);
const file = files[key];
const source = file.contents.toString();
const template = handlebars.compile(source, options);
const data = Object.assign({}, meta, file);
try {
file.contents = new Buffer(template(data));
debug('Processed ' + key);
} catch (e) {
console.log(e.message);
}
});
};
};
module.exports = plugin;