ok really im close now
This commit is contained in:
parent
22e9cb094d
commit
89759068e5
16 changed files with 53 additions and 87 deletions
39
hack/generate.ts
Normal file
39
hack/generate.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
import indexTemplate from "./templates/index.html.txt";
|
||||
import workTemplate from "./templates/work.html.txt";
|
||||
import readmeTemplate from "./templates/README.md.txt";
|
||||
import chalk from "chalk";
|
||||
import { mkdirSync } from "node:fs";
|
||||
|
||||
export const generate = async (works: string[]) => {
|
||||
const allWorks = works
|
||||
.map((file) => file.replace("src/", "").replace("/main.ts", ""))
|
||||
.sort()
|
||||
.reverse();
|
||||
|
||||
for (const work of allWorks) {
|
||||
const html = `${workTemplate}`.replace(/##name##/g, work);
|
||||
|
||||
mkdirSync(`html/${work}`, { recursive: true });
|
||||
await Bun.write(`html/${work}/index.html`, html);
|
||||
console.log(chalk.yellow(` -> html/${work}/index.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);
|
||||
console.log(chalk.yellow(` -> html/index.html...`));
|
||||
|
||||
const readme = readmeTemplate.replace(
|
||||
"<!--/INSERT/-->",
|
||||
allWorks
|
||||
.reverse()
|
||||
.map((work) => `- [./${work}](https://art.mekanoe.com/${work})`)
|
||||
.join("\n")
|
||||
);
|
||||
await Bun.write("README.md", readme);
|
||||
console.log(chalk.yellow(` -> README.md...`));
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue