the home site for me: also iteration 3 or 4 of my site

feat: update OG image generation script to create missing directories

Changed files
+21 -3
tools
+1 -1
package.json
···
"module": "index.ts",
"type": "module",
"scripts": {
-
"build:all": "zola build; bun run tools/genOG.ts"
+
"gen": "bun run tools/genOG.ts"
},
"devDependencies": {
"@types/bun": "latest"
+20 -2
tools/genOG.ts
···
import puppeteer from "puppeteer";
-
import { readdir } from "node:fs/promises";
+
import { readdir, mkdir } from "node:fs/promises";
const template = await Bun.file("tools/og.html").text();
···
file.endsWith("index.html")
);
+
const directories = new Set(
+
files.map((file) => file.replace("index.html", ""))
+
);
+
+
const existing = (await readdir("static/")).filter((file) =>
+
directories.has(file)
+
);
+
+
// create not existing
+
for (const dir of directories) {
+
if (!existing.includes(dir)) {
+
await mkdir(`static/${dir.split("/").slice(0, -1).join("/")}`, {
+
recursive: true,
+
});
+
}
+
}
+
console.log("Generating OG images for", files.length, "files");
// for each file, get the title tag from the index.html
···
console.error(`No title found for ${file}`);
continue;
}
+
console.log("Generating OG for", title);
-
await og(title, `public/${file.replace("index.html", "og.png")}`);
+
await og(title, `static/${file.replace("index.html", "og.png")}`);
}
} catch (e) {
console.error(e);