Files
e-tib.com/lib/og-helper.tsx
Marc Mintel c908fcb4b8
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 1m0s
Build & Deploy / 🧪 QA (push) Successful in 1m44s
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Post-Deploy Verification (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
Build & Deploy / 🏗️ Build (push) Has been cancelled
fix(og): use import.meta.url and fetch instead of readFileSync for next/og fonts
2026-06-21 23:12:29 +02:00

46 lines
1.1 KiB
TypeScript

import { readFileSync } from 'fs';
import { join } from 'path';
import { ImageResponse } from 'next/og';
/**
* Loads the Inter fonts for use in Satori (Next.js OG Image generation).
* Since we are using runtime = 'nodejs', we can read them from the filesystem.
*/
export async function getOgFonts() {
try {
const boldFontData = await fetch(
new URL('../public/fonts/Inter-Bold.ttf', import.meta.url)
).then((res) => res.arrayBuffer());
const regularFontData = await fetch(
new URL('../public/fonts/Inter-Regular.ttf', import.meta.url)
).then((res) => res.arrayBuffer());
return [
{
name: 'Inter',
data: boldFontData,
style: 'normal' as const,
weight: 700 as const,
},
{
name: 'Inter',
data: regularFontData,
style: 'normal' as const,
weight: 400 as const,
},
];
} catch (error) {
console.error(`[OG] Failed to load fonts:`, error);
return [];
}
}
/**
* Common configuration for OG images
*/
export const OG_IMAGE_SIZE = {
width: 1200,
height: 630,
};