import { ImageResponse } from "next/og"; import { API_URL } from "@/config/constants"; import { buildAbsoluteUrl } from "@/app/seo"; export const size = { width: 1200, height: 630, }; export const contentType = "image/png"; type OpenGraphImageProps = { params: Promise<{ slug: string }>; }; async function getFacility(slug: string) { const res = await fetch(`${API_URL}/facilities/${slug}`, { cache: "no-store" }); return res.json(); } export default async function OpenGraphImage({ params }: OpenGraphImageProps) { const { slug } = await params; const facility = await getFacility(slug); const title = facility?.name || "TeeOff"; const location = [facility?.city, facility?.county].filter(Boolean).join(" ยท ") || "Norske golfanlegg"; const imageUrl = facility?.image_url ? buildAbsoluteUrl(facility.image_url) : null; return new ImageResponse( (
{imageUrl ? ( {title} ) : null}
TeeOff
Golfbane
{title}
{location}
), size, ); }