From 7a70057e2ce7c573e15339dbc548862ecb2790a2 Mon Sep 17 00:00:00 2001 From: Jake Jarvis Date: Mon, 24 Mar 2025 16:55:19 -0400 Subject: [PATCH] glowed up open graph images --- app/notes/[slug]/opengraph-image.tsx | 195 ++++++++++++++++++++------- next.config.ts | 1 + 2 files changed, 145 insertions(+), 51 deletions(-) diff --git a/app/notes/[slug]/opengraph-image.tsx b/app/notes/[slug]/opengraph-image.tsx index 199b6a4f..22e2d3d5 100644 --- a/app/notes/[slug]/opengraph-image.tsx +++ b/app/notes/[slug]/opengraph-image.tsx @@ -56,68 +56,155 @@ const Image = async ({ params }: { params: Promise<{ slug: string }> }) => { // get the post's title and image filename from its frontmatter const frontmatter = await getFrontMatter(slug); + // template is HEAVILY inspired by https://og-new.clerkstage.dev/ return new ImageResponse( (
- {frontmatter!.image && ( -
- {/* eslint-disable-next-line jsx-a11y/alt-text */} - -
- )} - {AVATAR_PATH && ( -
- {/* eslint-disable-next-line jsx-a11y/alt-text */} - -
- )} +
')`, + backgroundRepeat: "repeat", + }} + >
+ +
')`, + maskImage: "radial-gradient(rgb(0, 0, 0) 0%, rgba(0, 0, 0, 0) 80%)", + }} + >
+
- {frontmatter!.title} + +
+ +
+
+
+ + Notes + +
+ +
+ {frontmatter!.title} +
+ +
+ {new Date(frontmatter!.date).toLocaleDateString("en-US", { + year: "numeric", + month: "long", + day: "numeric", + })} +
+
+ + {frontmatter!.image && ( +
+ +
+ )}
), @@ -125,12 +212,18 @@ const Image = async ({ params }: { params: Promise<{ slug: string }> }) => { ...size, fonts: [ { - name: "Geist", + name: "Geist-Regular", // load the Geist font directly from its npm package // IMPORTANT: include this exact path in next.config.ts under "outputFileTracingIncludes" + data: await readFile(join(process.cwd(), "node_modules/geist/dist/fonts/geist-sans/Geist-Regular.ttf")), + style: "normal", + weight: 400, + }, + { + name: "Geist-SemiBold", data: await readFile(join(process.cwd(), "node_modules/geist/dist/fonts/geist-sans/Geist-SemiBold.ttf")), style: "normal", - weight: 600, + weight: 700, }, ], } diff --git a/next.config.ts b/next.config.ts index a4d61bc8..4764f74a 100644 --- a/next.config.ts +++ b/next.config.ts @@ -24,6 +24,7 @@ const nextConfig: NextConfig = { "/notes/[slug]/opengraph-image": [ "./notes/**/*", "./app/opengraph-image.jpg", + "./node_modules/geist/dist/fonts/geist-sans/Geist-Regular.ttf", "./node_modules/geist/dist/fonts/geist-sans/Geist-SemiBold.ttf", ], },