diff --git a/app/api/og/route.tsx b/app/api/og/route.tsx new file mode 100644 index 0000000..e384b93 --- /dev/null +++ b/app/api/og/route.tsx @@ -0,0 +1,74 @@ +import { NextRequest } from "next/server"; +import { ImageResponse } from "next/og"; +import { siteConfig } from "@/config/site"; + +export const runtime = "edge"; + +const interBold = fetch( + new URL("../../../assets/fonts/Inter-Bold.ttf", import.meta.url), +).then((res) => res.arrayBuffer()); + +export async function GET(req: NextRequest) { + try { + const fontBold = await interBold; + + const { searchParams } = req.nextUrl; + const title = searchParams.get("title"); + + if (!title) { + return new Response("No title provided", { status: 500 }); + } + + const heading = + title.length > 140 ? `${title.substring(0, 140)}...` : title; + + return new ImageResponse( + ( +
+
+ + + + + +

JollyBlog

+
+
+
+ BLOG POST +
+
{heading}
+
+
+
{siteConfig.url}
+
+
{siteConfig.links.github}
+
+
+
+ ), + { + width: 1200, + height: 630, + fonts: [ + { + name: "Inter", + data: fontBold, + style: "normal", + weight: 700, + }, + ], + }, + ); + } catch (error) { + return new Response("Failed to generate image", { status: 500 }); + } +} diff --git a/app/opengraph-image.png b/app/opengraph-image.png new file mode 100644 index 0000000..c9f6670 Binary files /dev/null and b/app/opengraph-image.png differ diff --git a/assets/fonts/Inter-Bold.ttf b/assets/fonts/Inter-Bold.ttf new file mode 100644 index 0000000..8e82c70 Binary files /dev/null and b/assets/fonts/Inter-Bold.ttf differ