?
This commit is contained in:
parent
16a298624f
commit
6e0a128cdf
1 changed files with 0 additions and 0 deletions
30
src/app/blog/[slug]/page.tsx
Normal file
30
src/app/blog/[slug]/page.tsx
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { notFound } from "next/navigation";
|
||||
import { readdirSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
export async function generateStaticParams() {
|
||||
const blogDir = join(process.cwd(), "src/app/blog/posts");
|
||||
const files = readdirSync(blogDir).filter((file) => file.endsWith(".mdx"));
|
||||
|
||||
return files.map((file) => ({
|
||||
slug: file.replace(".mdx", ""),
|
||||
}));
|
||||
}
|
||||
|
||||
export default async function BlogPost({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ slug: string }>;
|
||||
}) {
|
||||
const { slug } = await params;
|
||||
|
||||
try {
|
||||
const Post = (
|
||||
await import(`@/app/blog/posts/${slug}.mdx`)
|
||||
).default;
|
||||
|
||||
return <Post />;
|
||||
} catch {
|
||||
notFound();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue