import { ImageResponse } from "next/og"; import { readFile } from "node:fs/promises"; import { join } from "node:path"; export { getPageTitle } from "@/lib/page-titles"; type FontCache = { geistRegular: Buffer; geistPixelSquare: Buffer; }; let fontCache: FontCache | null = null; async function loadFonts(): Promise { if (fontCache) return fontCache; const [geistRegular, geistPixelSquare] = await Promise.all([ readFile(join(process.cwd(), "public/Geist-Regular.ttf")), readFile(join(process.cwd(), "public/GeistPixel-Square.ttf")), ]); fontCache = { geistRegular, geistPixelSquare }; return fontCache; } export async function renderOgImage(title: string): Promise { const { geistRegular, geistPixelSquare } = await loadFonts(); return new ImageResponse( (
/ zero
{title.split("\n").map((line, i) => ( {line} ))}
), { width: 1200, height: 630, fonts: [ { name: "Geist", data: geistRegular, style: "normal", weight: 400, }, { name: "GeistPixelSquare", data: geistPixelSquare, style: "normal", weight: 400, }, ], }, ); }