pass the whole router to MDX
This commit is contained in:
parent
d54e91de4d
commit
ae827f515d
3 changed files with 8 additions and 7 deletions
|
@ -1,5 +1,7 @@
|
||||||
# supMDX
|
# supMDX
|
||||||
A template to make blog-like site with MDX
|
A template to make blog-like site with MDX and next.js
|
||||||
|
|
||||||
|
Note that this template is still in development and may change without compatibility
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
- `supMDX.yml`
|
- `supMDX.yml`
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
|
import type {AppProps} from 'next/app';
|
||||||
import Nav from './Nav';
|
import Nav from './Nav';
|
||||||
import Footer from './Footer';
|
import Footer from './Footer';
|
||||||
import MetaInfo from './MetaInfo';
|
import MetaInfo from './MetaInfo';
|
||||||
|
@ -6,9 +7,7 @@ import type {HeadingInfo} from '@sup39/rehype-mdx-export-headings';
|
||||||
|
|
||||||
export type MDXProps = {
|
export type MDXProps = {
|
||||||
children: JSX.Element
|
children: JSX.Element
|
||||||
data: {
|
router: AppProps['router'],
|
||||||
pathname: string,
|
|
||||||
},
|
|
||||||
meta: Partial<{
|
meta: Partial<{
|
||||||
title: string
|
title: string
|
||||||
description: string
|
description: string
|
||||||
|
@ -18,7 +17,7 @@ export type MDXProps = {
|
||||||
headings: HeadingInfo[]
|
headings: HeadingInfo[]
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function MDXRoot({children, data: {pathname}, meta={}, headings}: MDXProps) {
|
export default function MDXRoot({children, router: {pathname}, meta={}, headings}: MDXProps) {
|
||||||
const {title, description} = meta;
|
const {title, description} = meta;
|
||||||
const h1 = meta.h1 ?? title;
|
const h1 = meta.h1 ?? title;
|
||||||
return <>
|
return <>
|
||||||
|
|
|
@ -13,8 +13,8 @@ const extendedHx = Object.fromEntries(hx.map(H => [H,
|
||||||
</H>,
|
</H>,
|
||||||
]));
|
]));
|
||||||
|
|
||||||
export default function App({Component, pageProps, router: {pathname}}: AppProps) {
|
export default function App({Component, pageProps, router}: AppProps) {
|
||||||
return <MDXProvider components={{S, ...extendedHx}}>
|
return <MDXProvider components={{S, ...extendedHx}}>
|
||||||
<Component data={{pathname}} {...pageProps} />
|
<Component router={router} {...pageProps} />
|
||||||
</MDXProvider>;
|
</MDXProvider>;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue