|
| 1 | +/* eslint-disable import/no-extraneous-dependencies */ |
| 2 | +import { generateStaticParamsFor, importPage } from 'nextra/pages'; |
| 3 | +import { NextPageProps } from '@theguild/components'; |
| 4 | +import { useMDXComponents } from '../../../../../mdx-components.js'; |
| 5 | +import { ConfiguredGiscus } from '../../../../components/configured-giscus'; |
| 6 | + |
| 7 | +/** |
| 8 | + * You might have an urge to try to refactor this to a separate file and reuse between product-updates and docs. |
| 9 | + * I had the same urge. It's absurdly finicky. I warned you. |
| 10 | + * |
| 11 | + * BTW, even if we moved the product updates to page.mdx pattern, we still need this nesting to fix links in sidebar. |
| 12 | + */ |
| 13 | +export const generateStaticParams = async () => { |
| 14 | + const pages = await generateStaticParamsFor('mdxPath')(); |
| 15 | + return pages |
| 16 | + .map(page => (page.mdxPath[0] === 'docs' ? { mdxPath: page.mdxPath.slice(1) } : null)) |
| 17 | + .filter(Boolean); |
| 18 | +}; |
| 19 | + |
| 20 | +export async function generateMetadata(props: NextPageProps<'...mdxPath'>) { |
| 21 | + const params = await props.params; |
| 22 | + const { metadata } = await importPage(['docs', ...(params.mdxPath || [])]); |
| 23 | + return metadata; |
| 24 | +} |
| 25 | + |
| 26 | +const Wrapper = useMDXComponents().wrapper; |
| 27 | + |
| 28 | +export default async function Page(props: NextPageProps<'...mdxPath'>) { |
| 29 | + const params = await props.params; |
| 30 | + |
| 31 | + const result = await importPage(['docs', ...(params.mdxPath || [])]); |
| 32 | + const { default: MDXContent, toc, metadata } = result; |
| 33 | + |
| 34 | + return ( |
| 35 | + <Wrapper toc={toc} metadata={metadata}> |
| 36 | + <MDXContent params={params} /> |
| 37 | + <ConfiguredGiscus /> |
| 38 | + </Wrapper> |
| 39 | + ); |
| 40 | +} |
0 commit comments