fix: og image with resvg client
Some checks failed
Build & Deploy / build-and-deploy (push) Failing after 20s

This commit is contained in:
svemagie
2026-03-31 20:45:13 +02:00
parent 352a25552c
commit 2b9e425c98

View File

@@ -8,7 +8,7 @@
*/
import satori from "satori";
import { Resvg } from "@resvg/resvg-js";
import { spawnSync } from "node:child_process";
import {
readFileSync,
writeFileSync,
@@ -482,12 +482,20 @@ export async function generateOgImages(contentDir, cacheDir, siteName, batchSize
const card = buildCard(title, description, date, postType, siteName);
const svg = await satori(card, { width: WIDTH, height: HEIGHT, fonts });
const resvg = new Resvg(svg, {
fitTo: { mode: "width", value: WIDTH },
});
const pngBuffer = resvg.render().asPng();
writeFileSync(join(ogDir, `${slug}.png`), pngBuffer);
// Render SVG to PNG using the system resvg CLI
// Requires: pkg install resvg
const outPath = join(ogDir, `${slug}.png`);
const resvgProc = spawnSync(
"resvg",
["-w", String(WIDTH), "-b", COLORS.bg, "-o", outPath, "-"],
{ input: svg, encoding: "buffer" }
);
if (resvgProc.error) {
throw resvgProc.error;
}
if (resvgProc.status !== 0) {
throw new Error(`resvg CLI failed: ${resvgProc.stderr?.toString()}`);
}
newManifest[slug] = { title: slug, hash };
generated++;