import { ImageResponse } from 'next/og' import { readFile } from 'node:fs/promises' import { join } from 'node:path' import { findParent } from 'fumadocs-core/page-tree' import { source } from '@/lib/source' export const ogImageSize = { width: 1200, height: 630 } export const ogImageContentType = 'image/png' const fontsDir = join(process.cwd(), 'src/assets/fonts') // Satori cannot read the site stylesheet, so mirror Orca's canonical dark tokens here. const ogColors = { background: '#0a0a0a', foreground: '#fafafa', card: '#171717', secondary: '#262626', mutedForeground: '#a1a1a1', border: 'rgb(255 255 255 / 0.07)' } as const function getSectionLabel(url: string): string { const parent = findParent(source.pageTree, url) if (parent?.type === 'folder' && parent.name) { return String(parent.name) } return 'Documentation' } function getFooterTag(title: string, section: string): string { return `${title} - ${section} - Orca` } function getTitleFontSize(title: string): number { if (title.length > 40) { return 48 } if (title.length > 28) { return 60 } return 72 } export async function createDocsOgImage({ title, url }: { title: string; url: string }) { const section = getSectionLabel(url) const footerTag = getFooterTag(title, section) const titleFontSize = getTitleFontSize(title) const [logoData, geistRegular, geistBold] = await Promise.all([ readFile(join(process.cwd(), 'public/docs/logo.svg'), 'base64'), // next/og's Satori renderer accepts static TrueType fonts, while the // browser stylesheet uses the smaller variable WOFF2 variant. readFile(join(fontsDir, 'Geist-Regular.ttf')), readFile(join(fontsDir, 'Geist-Bold.ttf')) ]) const logoSrc = `data:image/svg+xml;base64,${logoData}` const regularFont = geistRegular.buffer.slice( geistRegular.byteOffset, geistRegular.byteOffset + geistRegular.byteLength ) const boldFont = geistBold.buffer.slice( geistBold.byteOffset, geistBold.byteOffset + geistBold.byteLength ) return new ImageResponse(