Skip to content

Commit

Permalink
generate og image for blog
Browse files Browse the repository at this point in the history
  • Loading branch information
loganzartman committed Nov 15, 2023
1 parent 7c65f98 commit a7bf038
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/app/blog/[slug]/opengraph-image.png/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {getAllPosts, getPostBySlug} from '@/app/blog/lib/posts';
import {generateOgImage} from '@/lib/generate-og-image';

export async function generateStaticParams() {
return getAllPosts().map(({data: {slug}}) => ({slug}));
}

export async function GET(req: Request, {params}: {params: {slug: string}}) {
const post = getPostBySlug(params.slug);
return generateOgImage({title: post.data.title});
}
3 changes: 3 additions & 0 deletions src/app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export function generateMetadata({params}: Props): Metadata {
return {
title: `${post.data.title} - loganz`,
description: post.data.description,
openGraph: {
images: `/blog/${params.slug}/opengraph-image.png`,
},
};
}

Expand Down

0 comments on commit a7bf038

Please sign in to comment.