-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpage.tsx
71 lines (63 loc) · 1.49 KB
/
page.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type { MDXComponents } from 'mdx/types';
import type { JSX } from 'react';
import {
H1ForTableOfContents,
H2ForTableOfContents,
H3ForTableOfContents,
H4ForTableOfContents,
H5ForTableOfContents,
H6ForTableOfContents,
TableOfContents,
TableOfContentsProvider,
} from './TableOfContents.tsx';
import { notFound } from 'next/navigation';
type RecipeMdxModule = {
default: (props: {
readonly components?: MDXComponents | undefined;
params: {
recipeSlug: string;
};
}) => JSX.Element;
metadata: {
title: string;
};
};
type Props = {
params: Promise<{
recipeSlug: string;
}>;
};
export default async function RecipePage(props: Props) {
const params = await props.params;
let recipeModule;
try {
recipeModule = (await import(
`./content/${params.recipeSlug}/index.mdx`
)) as RecipeMdxModule;
} catch {
notFound();
}
const MDXContent = recipeModule.default;
return (
<>
<h1>{recipeModule.metadata.title}</h1>
<TableOfContentsProvider>
<details>
<summary>Table of Contents</summary>
<TableOfContents />
</details>
<MDXContent
params={params}
components={{
h1: H1ForTableOfContents,
h2: H2ForTableOfContents,
h3: H3ForTableOfContents,
h4: H4ForTableOfContents,
h5: H5ForTableOfContents,
h6: H6ForTableOfContents,
}}
/>
</TableOfContentsProvider>
</>
);
}