port to OOP
This commit is contained in:
parent
7e8b1ad477
commit
e33936a86b
15 changed files with 918 additions and 158 deletions
42
generators/generate.ts
Normal file
42
generators/generate.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { unlinkSync } from "node:fs";
|
||||
import { globSync } from "glob";
|
||||
import indexTemplate from "./index.html.txt";
|
||||
import workTemplate from "./work.html.txt";
|
||||
import readmeTemplate from "./README.md.txt";
|
||||
|
||||
const allHtmls = globSync("html/*.html").filter(
|
||||
(file) => file !== "html/index.html"
|
||||
);
|
||||
for (const htmlFile of allHtmls) {
|
||||
unlinkSync(htmlFile);
|
||||
}
|
||||
|
||||
const allWorks = globSync("html/*.js")
|
||||
.map((file) => file.replace("html/", "").replace(".js", ""))
|
||||
.filter((work) => work !== "platform");
|
||||
|
||||
console.log({ allWorks });
|
||||
|
||||
for (const work of allWorks) {
|
||||
const html = `${workTemplate}`.replace(/##name##/g, work);
|
||||
|
||||
await Bun.write(`html/${work}.html`, html);
|
||||
}
|
||||
|
||||
const index = indexTemplate.replace(
|
||||
"<!--/INSERT/-->",
|
||||
allWorks.map((work) => `<li><a href="/${work}">./${work}</a></li>`).join("\n")
|
||||
);
|
||||
await Bun.write("html/index.html", index);
|
||||
|
||||
const readme = readmeTemplate.replace(
|
||||
"<!--/INSERT/-->",
|
||||
allWorks
|
||||
.map((work) => `- [./${work}](https://art.mekanoe.com/${work})`)
|
||||
.join("\n")
|
||||
);
|
||||
await Bun.write("README.md", readme);
|
||||
|
||||
console.log(
|
||||
`index.html & README.md generated. ${allWorks.length} works found.`
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue