mirror of
https://github.com/godotengine/godot-commit-artifacts.git
synced 2026-01-03 18:09:48 +03:00
Initial commit
This commit is contained in:
41
build/posthtml-include.js
Normal file
41
build/posthtml-include.js
Normal 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;
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user