import { ImageResponse } from "next/og"; import { readFile } from "node:fs/promises"; import { join } from "node:path"; export { getPageTitle } from "@/lib/page-titles"; // Cache font data in memory after first load let fontCache: { geistRegular: Buffer } | null = null; async function loadFonts() { if (fontCache) return fontCache; const geistRegular = await readFile( join(process.cwd(), "public/Geist-Regular.ttf"), ); fontCache = { geistRegular }; return fontCache; } export async function renderOgImage(title: string) { const { geistRegular } = await loadFonts(); return new ImageResponse(
/ json-render
{title}
, { width: 1200, height: 630, fonts: [ { name: "Geist", data: geistRegular.buffer as ArrayBuffer, style: "normal", weight: 400, }, ], }, ); }