Initial commit

This commit is contained in:
Yuri Sizov
2023-03-28 16:06:15 +02:00
commit 91df762984
29 changed files with 3588 additions and 0 deletions

41
build/posthtml-include.js Normal file
View File

@@ -0,0 +1,41 @@
import fs from "fs";
import path from "path";
import parser from "posthtml-parser";
export default function(options) {
options = options || {};
options.root = options.root || './';
options.encoding = options.encoding || 'utf-8';
return function posthtmlInclude(tree) {
tree.match({ tag: 'include' }, function(node) {
if (!node.attrs.src) {
return {
tag: false,
content: null
};
}
const src = path.resolve(options.root, node.attrs.src);
const source = fs.readFileSync(src, options.encoding);
const subtree = parser(source);
subtree.match = tree.match;
const content = source.indexOf('include') !== -1? posthtmlInclude(subtree): subtree;
if (tree.messages) {
tree.messages.push({
type: "dependency",
file: src
});
}
return {
tag: false,
content: content
};
});
return tree;
};
};