import Link from 'next/link'
import { notFound } from 'next/navigation'
import { CustomMDX } from '@/components/mdx'
import PostHeader from '@/components/blog/PostHeader'
import ProgressBar from '@/components/blog/ProgressBar'
import { getAllPosts, getReadingTime, findAdjacentPosts } from '../utils'
import { baseUrl } from '../../sitemap'
export async function generateStaticParams() {
const posts = await getAllPosts()
return posts.map((post) => ({
slug: post.slug,
}))
}
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params
const post = (await getAllPosts()).find((p) => p.slug === slug)
if (!post) {
return {}
}
const {
title,
publishedAt: publishedTime,
summary: description,
image,
} = post.metadata
const ogImage = image
? image
: `${baseUrl}/og?title=${encodeURIComponent(title)}`
return {
title,
description,
openGraph: {
title,
description,
type: 'article',
publishedTime,
url: `${baseUrl}/blog/${post.slug}`,
images: [{ url: ogImage }],
},
twitter: {
card: 'summary_large_image',
title,
description,
images: [ogImage],
},
}
}
export default async function Blog({ params }: { params: Promise<{ slug: string }> }) {
const { slug } = await params;
const posts = await getAllPosts()
const post = posts.find((p) => p.slug === slug)
if (!post) {
notFound()
}
const reading = getReadingTime(post.content)
const { prev, next } = findAdjacentPosts(posts, slug)
return (
<>
← Back to blog
>
)
}