import { notFound } from "next/navigation"; import { MDXRemote } from "next-mdx-remote/rsc"; import { TRPCError } from "@trpc/server"; import matter from "gray-matter"; import { servTrpc } from "~/app/_trpc/ServerClient"; import { Badge } from "~/components/ui/badge"; import { mdxComponents } from "~/components/mdx-components"; type Props = { params: Promise<{ slug: string }>; }; export default async function BlogPostPage({ params }: Props) { const { slug } = await params; let post: Awaited>; try { post = await servTrpc.blog.metadataBySlug(slug); } catch (e) { if (e instanceof TRPCError && e.code === "NOT_FOUND") notFound(); throw e; } const response = await fetch(post.fileUrl, { next: { revalidate: 3600 } }); if (!response.ok) notFound(); const parsed = matter(await response.text()); const tags = Array.isArray(parsed.data.tags) ? parsed.data.tags.map((tag) => String(tag).trim()).filter(Boolean) : post.tags; const title = typeof parsed.data.title === "string" ? parsed.data.title : post.title; const date = typeof parsed.data.date === "string" ? parsed.data.date : post.date; return (

{title}

{date && ( )} {tags.length > 0 && (
{tags.map((tag) => ( {tag} ))}
)}
); }