-
Notifications
You must be signed in to change notification settings - Fork 0
/
[...slug].tsx
56 lines (48 loc) · 1.22 KB
/
[...slug].tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { getAllMdxNodes, getMdxNode, getMdxPaths } from "next-mdx/server"
import Link from "next/link"
import { Icon } from "reflexjs"
import { Snippet } from "../../src/snippet"
export default function PostPage({ post, snippets }) {
return (
<div variant="container.md" py="10">
<Link href="/" passHref>
<a variant="button.link">
<Icon name="arrow-left" mr="2" />
Back home
</a>
</Link>
<h1 variant="heading.h1">{post.frontMatter.title}</h1>
<p variant="text.lead" mt="2">
{post.frontMatter.excerpt}
</p>
{snippets?.map((snippet) => (
<div key={snippet.url} mt="10">
<Snippet snippet={snippet} />
</div>
))}
</div>
)
}
export async function getStaticPaths() {
return {
paths: await getMdxPaths("post"),
fallback: false,
}
}
export async function getStaticProps(context) {
const post = await getMdxNode("post", context)
if (!post) {
return {
notFound: true,
}
}
const snippets = await getAllMdxNodes("snippet")
return {
props: {
post,
snippets: snippets.filter((snippet) =>
snippet.relationships.post.some(({ slug }) => slug === post.slug)
),
},
}
}