-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90f3617
commit 177f6b8
Showing
5 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { posts } from "#site/content"; | ||
import { MDXContent } from "@/components/mdx-components"; | ||
import { notFound } from "next/navigation"; | ||
|
||
interface PostPageProps { | ||
params: { | ||
slug: string[]; | ||
}; | ||
} | ||
|
||
async function getPostFromParams(params: PostPageProps["params"]) { | ||
const slug = params?.slug?.join("/"); | ||
const post = posts.find((post) => post.slugAsParams === slug); | ||
|
||
return post; | ||
} | ||
|
||
export async function generateStaticParams(): Promise< | ||
PostPageProps["params"][] | ||
> { | ||
return posts.map((post) => ({ slug: post.slugAsParams.split("/") })); | ||
} | ||
|
||
export default async function PostPage({ params }: PostPageProps) { | ||
const post = await getPostFromParams(params); | ||
|
||
if (!post || !post.published) { | ||
notFound(); | ||
} | ||
|
||
return ( | ||
<article className="container py-6 prose dark:prose-invert max-w-3xl mx-auto"> | ||
<h1 className="mb 2">{post.title}</h1> | ||
{post.description ? ( | ||
<p className="text-xl mt-0 text-muted-foreground">{post.description}</p> | ||
) : null} | ||
<hr className="my-4" /> | ||
<MDXContent code={post.body} /> | ||
</article> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Image from "next/image"; | ||
import * as runtime from "react/jsx-runtime"; | ||
|
||
const useMDXComponent = (code: string) => { | ||
const fn = new Function(code); | ||
return fn({ ...runtime }).default; | ||
}; | ||
|
||
const components = { | ||
Image, | ||
}; | ||
|
||
interface MdxProps { | ||
code: string; | ||
} | ||
|
||
export function MDXContent({ code }: MdxProps) { | ||
const Component = useMDXComponent(code); | ||
return <Component components={components} />; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters