Files
cecilia/app/(pages)/blogs/[slug]/page.tsx

38 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import fs from "fs/promises";
interface PropsParams {
slug: string;
}
interface Props {
params: Promise<PropsParams>;
}
export default async function Page({ params }: Props) {
const { slug } = await params;
const { default: Post, metadata } = await import(`@/blogs/${slug}.mdx`);
return (
<>
<div className="mb-6 rounded-lg border border-gray-300 p-2 shadow-md">
<h2 className="p-1 text-center text-2xl font-bold tracking-wider">
{metadata.title}
</h2>
</div>
<p className="text-gray-600/80">{metadata.datetime}</p>
<div className="prose mt-2 max-w-none">
<Post />
</div>
</>
);
}
export async function generateStaticParams() {
const blogs = (await fs.readdir("blogs")).filter((name) =>
name.endsWith(".mdx"),
);
return blogs.map((name) => ({
slug: name.replace(/\.mdx$/, ""),
}));
}
export const dynamicParams = false;