-
Notifications
You must be signed in to change notification settings - Fork 0
/
.posthtmlfix
37 lines (33 loc) · 1.14 KB
/
.posthtmlfix
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
var parser = require('posthtml-parser');
var fs = require('fs');
var path = require('path');
module.exports = function(options) {
options = options || {};
options.root = options.root || './';
options.encoding = options.encoding || 'utf-8';
return function posthtmlInclude(tree) {
tree.match({ tag: 'include' }, function(node) {
var src = node.attrs.src || false,
content;
if (src) {
src = path.resolve(options.root, src);
content = parser(fs.readFileSync(src, options.encoding));
if (typeof options.addDependencyTo === 'object' &&
typeof options.addDependencyTo.addDependency === 'function') {
options.addDependencyTo.addDependency(src);
}
if (tree.messages) {
tree.messages.push({
type: "dependency",
file: src
});
}
}
return {
tag: false,
content: content
};
});
return tree;
};
};