···11+++
22-title = "All my writings"
22+title = "index of /blog"
33sort_by = "date"
44template = "blog.html"
55page_template = "blog-page.html"
+16-30
scripts/genOG.ts
···11import puppeteer from "puppeteer";
22import { readdir, mkdir, access } from "node:fs/promises";
33+import { resolve } from "node:path";
3444-const template = await Bun.file("scripts/og.html").text();
55+const fontsPath = `file://${resolve("static/fonts")}`;
66+const template = (await Bun.file("scripts/og.html").text()).replace(
77+ /\{\{fontsPath\}\}/g,
88+ fontsPath,
99+);
510611const browser = await puppeteer.launch({
712 args: ["--no-sandbox"],
···1116async function og(
1217 postname: string,
1318 type: string,
1414- by: string | undefined,
1519 outputPath: string,
1620 width = 1200,
1721 height = 630,
···2428 template
2529 .toString()
2630 .replace("{{postname}}", postname)
2727- .replace("{{type}}", type)
2828- .replace("{{by}}", by || ""),
3131+ .replace("{{type}}", type),
3232+ { waitUntil: "load" },
2933 );
30343135 await page.screenshot({ path: outputPath });
···4145}
42464347try {
4444- // check if the public/blog folder exists
4545- // if not exit
4646- // if it does, get all the folders and then get the title tag from the index.html
4747-4848 if (!(await pathExists("public/"))) {
4949 console.error("public/ does not exist");
5050 process.exit(1);
5151 }
52525353- // read all the files in the current directory filtering for index.htmls
5453 const files = (await readdir("public/", { recursive: true })).filter((file) =>
5554 file.endsWith("index.html"),
5655 );
···6362 directories.has(file),
6463 );
65646666- // create not existing
6765 for (const dir of directories) {
6866 if (!existing.includes(dir)) {
6967 await mkdir(`static/${dir.split("/").slice(0, -1).join("/")}`, {
···74727573 console.log("Generating OG images for", files.length, "files");
76747777- // for each file, get the title tag from the index.html
7878- for (const file of files) {
7575+ const tasks = files.map((file) => async () => {
7976 const index = await Bun.file(`public/${file}`).text();
8077 const title = index.match(/<title>(.*?)<\/title>/)[1];
8178 let type = "Page";
8282- let by: string | undefined;
8379 switch (file.split("/")[0]) {
8480 case "blog":
8585- type = "Blog";
8686- if (file.split("/")[1] !== "index.html") {
8787- by = "<p>A post ... yeah thats about it</p>";
8888- } else {
8989- by = "<p>All authored by me ... or are they???</p>";
9090- }
8181+ type = file.split("/")[1] !== "index.html" ? "Blog" : "Blog Index";
9182 break;
9283 case "verify":
9384 type = "Slash Page";
9494- by = "<p>So you can stalk me 💀</p>";
9585 break;
9686 case "pfp":
9787 type = "Slash Page";
9898- by = "<p>Want to stare at my pretty face?</p>";
9988 break;
10089 case "tags":
101101- if (file.split("/")[1] === "index.html") {
102102- type = "Tags";
103103- by = "<p>A total archive!</p>";
104104- } else {
105105- type = "Tag";
106106- by = "<p>Find more posts like this!</p>";
107107- }
9090+ type = file.split("/")[1] === "index.html" ? "Tags" : "Tag";
10891 break;
10992 case "index.html":
11093 type = "Root";
111111- by = "<p>Where it all begins</p>";
11294 break;
11395 }
1149611597 console.log("Generating OG for", file, "title:", title, "with type:", type);
116116- await og(title, type, by, `static/${file.replace("index.html", "og.png")}`);
9898+ await og(title, type, `static/${file.replace("index.html", "og.png")}`);
9999+ });
100100+101101+ for (let i = 0; i < tasks.length; i += 10) {
102102+ await Promise.all(tasks.slice(i, i + 10).map((t) => t()));
117103 }
118104} catch (e) {
119105 console.error(e);