import { Callout } from "@/components/mdx/Callout"; import MDXComponents from "@/components/mdx/MDXComponents"; import { Locale, LOCALES } from "@/i18n/routing"; import { getPosts } from "@/lib/getBlogs"; import { constructMetadata } from "@/lib/metadata"; import { BlogPost } from "@/types/blog"; import { Metadata } from "next"; import { MDXRemote } from "next-mdx-remote-client/rsc"; import { notFound } from "next/navigation"; type Params = Promise<{ locale: string; slug: string; }>; type MetadataProps = { params: Params; }; export async function generateMetadata({ params, }: MetadataProps): Promise { const { locale, slug } = await params; let { posts }: { posts: BlogPost[] } = await getPosts(locale); const post = posts.find((post) => post.slug === "/" + slug); if (!post) { return constructMetadata({ title: "404", description: "Page not found", noIndex: true, locale: locale as Locale, path: `/blog/${slug}`, canonicalUrl: `/blog/${slug}`, }); } return constructMetadata({ page: "blog", title: post.title, description: post.description, images: post.image ? [post.image] : [], locale: locale as Locale, path: `/blog/${slug}`, canonicalUrl: `/blog/${slug}`, }); } export default async function BlogPage({ params }: { params: Params }) { const { locale, slug } = await params; let { posts }: { posts: BlogPost[] } = await getPosts(locale); const post = posts.find((item) => item.slug === "/" + slug); if (!post) { return notFound(); } return (

{post.title}

{post.image && ( {post.title} )} {post.tags && post.tags.split(",").length ? (
{post.tags.split(",").map((tag) => { return (
{tag.trim()}
); })}
) : ( <> )} {post.description && {post.description}}
); } export async function generateStaticParams() { let posts = (await getPosts()).posts; // Filter out posts without a slug posts = posts.filter((post) => post.slug); return LOCALES.flatMap((locale) => posts.map((post) => { const slugPart = post.slug.replace(/^\//, "").replace(/^blog\//, ""); return { locale, slug: slugPart, }; }) ); }