1
1
mirror of https://github.com/theoludwig/theoludwig.git synced 2024-11-05 21:11:31 +01:00
.profile/apps/website/app/[locale]/blog/[slug]/page.tsx

59 lines
1.2 KiB
TypeScript
Raw Normal View History

import type { Metadata } from "next"
import { notFound } from "next/navigation"
import { getBlogPostBySlug, getBlogPosts } from "@repo/blog"
import { BlogPostUI } from "@repo/blog/BlogPostUI"
interface BlogPostPageProps {
params: {
slug: string
}
}
export const generateMetadata = async (
props: BlogPostPageProps,
): Promise<Metadata> => {
2023-08-01 17:44:08 +02:00
const blogPost = await getBlogPostBySlug(props.params.slug)
2023-08-01 18:59:45 +02:00
if (blogPost == null) {
return notFound()
}
2023-08-01 17:44:08 +02:00
const title = `${blogPost.frontmatter.title} | Théo LUDWIG`
const description = blogPost.frontmatter.description
return {
title,
description,
openGraph: {
title,
description,
},
twitter: {
title,
description,
},
}
}
export const generateStaticParams = async (): Promise<
Array<{ slug: string }>
> => {
const posts = await getBlogPosts()
return posts.map((post) => {
return {
slug: post.slug,
}
})
}
const BlogPostPage: React.FC<BlogPostPageProps> = async (props) => {
const { params } = props
const blogPost = await getBlogPostBySlug(params.slug)
if (blogPost == null) {
return notFound()
}
return <BlogPostUI blogPost={blogPost} />
}
export default BlogPostPage