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 satori from "satori";
|
||||||
import { Resvg } from "@resvg/resvg-js";
|
import { spawnSync } from "node:child_process";
|
||||||
import {
|
import {
|
||||||
readFileSync,
|
readFileSync,
|
||||||
writeFileSync,
|
writeFileSync,
|
||||||
@@ -482,12 +482,20 @@ export async function generateOgImages(contentDir, cacheDir, siteName, batchSize
|
|||||||
|
|
||||||
const card = buildCard(title, description, date, postType, siteName);
|
const card = buildCard(title, description, date, postType, siteName);
|
||||||
const svg = await satori(card, { width: WIDTH, height: HEIGHT, fonts });
|
const svg = await satori(card, { width: WIDTH, height: HEIGHT, fonts });
|
||||||
const resvg = new Resvg(svg, {
|
// Render SVG to PNG using the system resvg CLI
|
||||||
fitTo: { mode: "width", value: WIDTH },
|
// Requires: pkg install resvg
|
||||||
});
|
const outPath = join(ogDir, `${slug}.png`);
|
||||||
const pngBuffer = resvg.render().asPng();
|
const resvgProc = spawnSync(
|
||||||
|
"resvg",
|
||||||
writeFileSync(join(ogDir, `${slug}.png`), pngBuffer);
|
["-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 };
|
newManifest[slug] = { title: slug, hash };
|
||||||
generated++;
|
generated++;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user