add compiletimejs

This commit is contained in:
Soph :3 2024-08-02 05:13:09 +03:00
parent 48b0833401
commit 55a699c7fd
Signed by: sophie
GPG key ID: EDA5D222A0C270F2

View file

@ -0,0 +1,25 @@
import { Plugin } from "..";
export default class CompileTimeJS extends Plugin {
name = "compile-time-js";
rewriteTriggers = ["html", "*"]
longLasting = false;
build = undefined;
async rewriteFile(file: string, filePath: string): Promise<string> {
let input = file;
const regex = /{&(.+)&}/gm;
let m;
while ((m = regex.exec(file)) !== null) {
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
input = file.slice(0, m.index) + eval(m[1]) + file.slice(m.index + m[0].length);
}
return input;
}
}