import { ImageResponse } from "@vercel/og"; import { ogImageSchema } from "@/lib/validations/og"; export const runtime = "edge"; const interRegular = fetch( new URL("../../../assets/fonts/Inter-Regular.ttf", import.meta.url), ).then((res) => res.arrayBuffer()); const interBold = fetch( new URL("../../../assets/fonts/CalSans-SemiBold.ttf", import.meta.url), ).then((res) => res.arrayBuffer()); export async function GET(req: Request) { try { const fontRegular = await interRegular; const fontBold = await interBold; const url = new URL(req.url); const values = ogImageSchema.parse(Object.fromEntries(url.searchParams)); const heading = values.heading.length > 80 ? `${values.heading.substring(0, 100)}...` : values.heading; const { mode } = values; const paint = mode === "dark" ? "#fff" : "#000"; const fontSize = heading.length > 80 ? "60px" : "80px"; const githubName = "oiov"; return new ImageResponse( (
WR.DO
{values.type}
{/* Title */}
{heading}
{/* eslint-disable-next-line @next/next/no-img-element */} avatar
{githubName}
Open Source Designer
github.com/mickasmt/next-auth-roles-template
), { width: 1200, height: 630, fonts: [ { name: "Inter", data: fontRegular, weight: 400, style: "normal", }, { name: "Cal Sans", data: fontBold, weight: 700, style: "normal", }, ], }, ); } catch (error) { return new Response(`Failed to generate image`, { status: 500, }); } }