import { ImageResponse } from 'next/og' import { SimLogoFull } from '@/app/(landing)/components/og-sim-logo' const size = { width: 1200, height: 630, } const TITLE_FONT_SIZE = { large: 64, medium: 56, small: 48, } as const function getTitleFontSize(title: string): number { if (title.length > 42) return TITLE_FONT_SIZE.small if (title.length > 26) return TITLE_FONT_SIZE.medium return TITLE_FONT_SIZE.large } async function loadGoogleFont( font: string, weights: string, text: string ): Promise { try { const url = `https://fonts.googleapis.com/css2?family=${font}:wght@${weights}&text=${encodeURIComponent(text)}` const css = await (await fetch(url)).text() const resource = css.match(/src: url\(([^)]+)\) format\('(opentype|truetype|woff2?)'\)/) if (resource) { const response = await fetch(resource[1]) if (response.status === 200) { return await response.arrayBuffer() } } } catch { return null } return null } interface LandingOgImageProps { eyebrow: string title: string subtitle: string pills?: string[] domainLabel?: string } /** Shared dynamic OG image for landing catalog pages (models, integrations). */ export async function createLandingOgImage({ eyebrow, title, subtitle, pills = [], domainLabel = 'sim.ai', }: LandingOgImageProps) { const text = `${eyebrow}${title}${subtitle}${pills.join('')}${domainLabel}` const [regularFontData, mediumFontData] = await Promise.all([ loadGoogleFont('Geist', '400', text), loadGoogleFont('Geist', '500', text), ]) return new ImageResponse(
{eyebrow} {title} {subtitle} {pills.length > 0 ? (
{pills.slice(0, 4).map((pill) => (
{pill}
))}
) : null}
{domainLabel}
, { ...size, fonts: [ ...(regularFontData ? [ { name: 'Geist', data: regularFontData, style: 'normal' as const, weight: 400 as const, }, ] : []), ...(mediumFontData ? [ { name: 'Geist', data: mediumFontData, style: 'normal' as const, weight: 500 as const, }, ] : []), ], } ) }