From 763533601c6f54545485d02b4c812da8d703a573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Sali=C3=A9s=20Brum?= Date: Fri, 13 Dec 2024 00:06:40 -0400 Subject: [PATCH] Update --- app/posts/[slug]/page.tsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/posts/[slug]/page.tsx b/app/posts/[slug]/page.tsx index 0b05dd1..9882d78 100644 --- a/app/posts/[slug]/page.tsx +++ b/app/posts/[slug]/page.tsx @@ -3,6 +3,12 @@ import { CustomMDX } from '../../components/mdx' import { formatDate, getBlogPosts } from '../../posts/utils' import { baseUrl } from '../../sitemap' +interface PageProps { + params: Promise<{ + slug: string; + }>; +} + export async function generateStaticParams() { let posts = await getBlogPosts() @@ -11,8 +17,10 @@ export async function generateStaticParams() { })) } -export async function generateMetadata({ params }: { params: { slug: string } }) { - const post = (await getBlogPosts()).find((post) => post.slug === params.slug) +export async function generateMetadata({ params }: PageProps) { + const { slug } = await params; + const posts = await getBlogPosts(); + const post = posts.find((post) => post.slug === slug); if (!post) return let { @@ -49,8 +57,12 @@ export async function generateMetadata({ params }: { params: { slug: string } }) } } -export default async function Blog({ params }: { params: { slug: string } }) { - const post = (await getBlogPosts()).find((post) => post.slug === params.slug) +export default async function Blog({ params }: PageProps) { + // const post = (await getBlogPosts()).find((post) => post.slug === params.slug) + const { slug } = await params; + const posts = await getBlogPosts(); + const post = posts.find((post) => post.slug === slug); + if (!post) notFound() return (