-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Checkout docs/[[...mdxPath]]/page.tsx
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 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,39 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import { generateStaticParamsFor, importPage } from 'nextra/pages'; | ||
import { useMDXComponents } from '../../../../mdx-components.js'; | ||
import { ConfiguredGiscus } from '../../../components/configured-giscus'; | ||
|
||
/** | ||
* You might have an urge to try to refactor this to a separate file and reuse between product-updates and docs. | ||
* I had the same urge. It's absurdly finicky. I warned you. | ||
* | ||
* BTW, even if we moved the product updates to page.mdx pattern, we still need this nesting to fix links in sidebar. | ||
*/ | ||
export const generateStaticParams = async () => { | ||
const pages = await generateStaticParamsFor('mdxPath')(); | ||
return pages | ||
.map(page => (page.mdxPath[0] === 'docs' ? { mdxPath: page.mdxPath.slice(1) } : null)) | ||
.filter(Boolean); | ||
}; | ||
|
||
export async function generateMetadata(props: PageProps<'...mdxPath'>) { | ||
const params = await props.params; | ||
const { metadata } = await importPage(['docs', ...(params.mdxPath || [])]); | ||
return metadata; | ||
} | ||
|
||
const Wrapper = useMDXComponents().wrapper; | ||
|
||
export default async function Page(props: PageProps<'...mdxPath'>) { | ||
const params = await props.params; | ||
|
||
const result = await importPage(['docs', ...(params.mdxPath || [])]); | ||
const { default: MDXContent, toc, metadata } = result; | ||
|
||
return ( | ||
<Wrapper toc={toc} metadata={metadata}> | ||
<MDXContent params={params} /> | ||
<ConfiguredGiscus /> | ||
</Wrapper> | ||
); | ||
} |