move blog to tsx
All checks were successful
/ test (push) Successful in 12s

This commit is contained in:
Soph :3 2024-07-23 11:51:16 +03:00
parent a7aaff537f
commit 262032b4e3
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
7 changed files with 186 additions and 78 deletions

View file

@ -11,37 +11,46 @@ export default class TSCompiler extends Plugin {
minify = false;
constructor() {
super();
if(process.argv.includes("--prod")) {
if (process.argv.includes("--prod")) {
this.minify = true;
}
}
async rewriteFile(file: string, filePath: string) {
const result = await esbuild.build({
stdin: {
contents: file,
resolveDir: filePath.split("/")?.slice(0,-1).join("/"),
sourcefile: filePath.split("/").at(-1),
loader: filePath.split("/").at(-1)?.split(".").at(-1) as "ts"|"tsx"|"jsx"
},
jsxFragment: "Fragment",
jsxFactory: "Nano.h",
jsxImportSource: "nano-jsx",
jsx: "transform",
write: false,
bundle: true,
outdir: 'out',
minify: this.minify,
});
let result;
try {
result = await esbuild.build({
stdin: {
contents: file,
resolveDir: filePath.split("/")?.slice(0, -1).join("/"),
sourcefile: filePath.split("/").at(-1),
loader: filePath.split("/").at(-1)?.split(".").at(-1) as
| "ts"
| "tsx"
| "jsx",
},
jsxFragment: "Fragment",
jsxFactory: "Nano.h",
jsxImportSource: "nano-jsx",
jsx: "transform",
write: false,
bundle: true,
outdir: "out",
minify: this.minify,
});
} catch (e) {
console.error(e);
console.log("Errored!");
return;
}
if(result.errors.length != 0) {
console.log("TS compiler errored.")
result.errors.forEach(element => {
console.error(element);
});
if (result.errors.length != 0) {
console.log("TS compiler errored.");
result.errors.forEach((element) => {
console.error(element);
});
} else {
const output = result.outputFiles[0].contents;
return (new TextDecoder()).decode(output);
return new TextDecoder().decode(output);
}
}
}

View file

@ -13,7 +13,7 @@ export default class Variables extends Plugin {
constructor() {
super();
this.variables["__BLOG_POSTS__"] = JSON.stringify(
fs.readdirSync("./website/blogs")
fs.readdirSync("./website/blogs").map((z) => z.replace(".md", ""))
);
const templatePath = path.resolve(__dirname, "../../website/templates");
if (fs.existsSync(templatePath)) {