From 79db8108ea89b6b6a19aeb516e9d6ada99afcdc7 Mon Sep 17 00:00:00 2001 From: Flummi Date: Sat, 25 Dec 2021 14:14:17 +0100 Subject: [PATCH] @mtime() --- src/template.mjs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/template.mjs b/src/template.mjs index ee58f94..f295515 100644 --- a/src/template.mjs +++ b/src/template.mjs @@ -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; + } + } };