From c908fcb4b899289ae9c750d98c8ba62fca2f0790 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Sun, 21 Jun 2026 23:12:29 +0200 Subject: [PATCH] fix(og): use import.meta.url and fetch instead of readFileSync for next/og fonts --- lib/og-helper.tsx | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/og-helper.tsx b/lib/og-helper.tsx index fcd5ad6fa..9e750a6a9 100644 --- a/lib/og-helper.tsx +++ b/lib/og-helper.tsx @@ -7,44 +7,31 @@ import { ImageResponse } from 'next/og'; * Since we are using runtime = 'nodejs', we can read them from the filesystem. */ export async function getOgFonts() { - const boldFontPath = join(process.cwd(), 'public/fonts/Inter-Bold.ttf'); - const regularFontPath = join(process.cwd(), 'public/fonts/Inter-Regular.ttf'); - try { - console.log(`[OG] Loading fonts: bold=${boldFontPath}, regular=${regularFontPath}`); - const boldFontBuffer = readFileSync(boldFontPath); - const regularFontBuffer = readFileSync(regularFontPath); + const boldFontData = await fetch( + new URL('../public/fonts/Inter-Bold.ttf', import.meta.url) + ).then((res) => res.arrayBuffer()); - // Satori (Vercel OG) strictly requires an ArrayBuffer, not a Node Buffer view. - const boldFont = boldFontBuffer.buffer.slice( - boldFontBuffer.byteOffset, - boldFontBuffer.byteOffset + boldFontBuffer.byteLength, - ); - const regularFont = regularFontBuffer.buffer.slice( - regularFontBuffer.byteOffset, - regularFontBuffer.byteOffset + regularFontBuffer.byteLength, - ); - - console.log( - `[OG] Fonts loaded successfully (${boldFont.byteLength} and ${regularFont.byteLength} bytes)`, - ); + const regularFontData = await fetch( + new URL('../public/fonts/Inter-Regular.ttf', import.meta.url) + ).then((res) => res.arrayBuffer()); return [ { name: 'Inter', - data: boldFont, - weight: 700 as const, + data: boldFontData, style: 'normal' as const, + weight: 700 as const, }, { name: 'Inter', - data: regularFont, - weight: 400 as const, + data: regularFontData, style: 'normal' as const, + weight: 400 as const, }, ]; } catch (error) { - console.error(`[OG] Failed to load fonts from ${process.cwd()}:`, error); + console.error(`[OG] Failed to load fonts:`, error); return []; } }