This commit is contained in:
Flummi 2021-12-25 14:14:17 +01:00
parent 218a925599
commit 79db8108ea

View File

@ -80,6 +80,8 @@ export default class {
.replace(/@js/g, "`);") // inject bare javascript
.replace(/@endjs/g, ";__html.push(`")
.replace(/@mtime\((.*?)\)/g, `\`);__html.push(this.getMtime('$1'));__html.push(\``)
.replace(/@include\((.*?)\)/g, (_, inc) => this.render(inc, data)) // include template
.replace(/@for\((.*?)\)$/gm, `\`);for($1){__html.push(\``)
@ -96,7 +98,8 @@ export default class {
return (new Function("_data", code)).bind({
escape: this.escape,
forEach: this.forEach
forEach: this.forEach,
getMtime: this.getMtime
})(data);
} catch(err) {
console.log(file, err.message);
@ -124,4 +127,13 @@ export default class {
else
throw new Error(`${o} is not a iterable object`);
};
getMtime(file) {
try {
return +(fs.statSync(path.normalize(process.cwd() + file)).mtimeMs + '').split(".")[0];
} catch(err) {
console.log(err);
return 0;
}
}
};