import satori from "satori"; import React from "react"; import { readFile } from "node:fs/promises"; import { Resvg } from "@resvg/resvg-js"; export const generateOpenGraph = async ( title: string, description: string, date?: Date, ) => { const nixLogoSvg = await readFile("./public/svg/nix.svg", "utf-8"); const nixLogoDataUrl = `data:image/svg+xml;base64,${Buffer.from(nixLogoSvg).toString("base64")}`; const formattedDate = date ? new Date(date).toLocaleDateString("en-GB", { year: "numeric", month: "long", day: "numeric", }) : null; const svg = await satori(
Nix Logo
isabelroses.com

30 ? "42px" : "52px", fontWeight: "700", color: "#ffffff", margin: "0", lineHeight: 1.1, maxWidth: "90%", letterSpacing: "-0.02em", }} > {title}

{description.length <= 100 ? description : description.substring(0, 97) + "..."}

{formattedDate && (
{formattedDate}
)}
, { width: 1200, height: 630, fonts: [ { name: "IBM Plex Mono", weight: 400, style: "normal", data: await readFile("./src/lib/ibm-plex-mono.regular.ttf"), }, ], }, ); const resvg = new Resvg(svg, { background: "#000000", }); const pngData = resvg.render(); const pngBuffer = pngData.asPng(); return new Uint8Array(pngBuffer); };