import { ImageResponse } from "next/og" import { OG_CONTENT_TYPE, OG_SIZE, ellipsize, resolveBrandLogoUrl } from "@/app/api/og/_shared" import { getDeveloperSummaryById } from "@/lib/data-backend" import { routeIdFromSegments } from "@/lib/utils" export const runtime = "nodejs" /** * Dynamic OpenGraph image for a developer page. Pulls the developer's * model + evaluation counts out of the same summary the page uses so the * unfurl identifies the specific developer rather than rendering the * generic site card. Co-located under /api/og/ rather than as an * `opengraph-image.tsx` sibling of the page because Next.js 15 rejects * metadata files inside catch-all (`[...id]`) folders. */ export async function GET( request: Request, context: { params: Promise<{ id: string | string[] }> }, ) { const { id } = await context.params const routeId = routeIdFromSegments(id) let developerName = "Developer" let modelCount: number | null = null let evaluationCount: number | null = null try { const summary = await getDeveloperSummaryById(routeId) if (summary) { developerName = summary.developer ?? developerName modelCount = summary.model_count ?? summary.models?.length ?? null evaluationCount = summary.evaluation_count ?? null } } catch { // Fall through to the generic card. } const logoUrl = resolveBrandLogoUrl(request) const displayName = ellipsize(developerName, 64) const response = new ImageResponse( (
{/* eslint-disable-next-line @next/next/no-img-element */}
Evaluation Cards
Developer
Developer
{displayName}
{(modelCount != null || evaluationCount != null) && (
{[ modelCount != null ? `${modelCount.toLocaleString("en-US")} ${modelCount === 1 ? "model" : "models"}` : null, evaluationCount != null ? `${evaluationCount.toLocaleString("en-US")} ${evaluationCount === 1 ? "result" : "results"}` : null, ] .filter(Boolean) .join(" · ")}
)}
Reproducibility · Completeness · Provenance · Comparability
Evaluation Cards
), OG_SIZE, ) response.headers.set("content-type", OG_CONTENT_TYPE) response.headers.set("cache-control", "public, max-age=3600, s-maxage=86400") return response }