fix: og image with resvg client
Some checks failed
Build & Deploy / build-and-deploy (push) Failing after 20s
Some checks failed
Build & Deploy / build-and-deploy (push) Failing after 20s
This commit is contained in:
22
lib/og.js
22
lib/og.js
@@ -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++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user