pass the whole router to MDX

This commit is contained in:
sup39 2022-11-05 22:21:49 +09:00
parent d54e91de4d
commit ae827f515d
3 changed files with 8 additions and 7 deletions

View file

@ -1,5 +1,7 @@
# 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
- `supMDX.yml`

View file

@ -1,4 +1,5 @@
import Head from 'next/head';
import type {AppProps} from 'next/app';
import Nav from './Nav';
import Footer from './Footer';
import MetaInfo from './MetaInfo';
@ -6,9 +7,7 @@ import type {HeadingInfo} from '@sup39/rehype-mdx-export-headings';
export type MDXProps = {
children: JSX.Element
data: {
pathname: string,
},
router: AppProps['router'],
meta: Partial<{
title: string
description: string
@ -18,7 +17,7 @@ export type MDXProps = {
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 h1 = meta.h1 ?? title;
return <>

View file

@ -13,8 +13,8 @@ const extendedHx = Object.fromEntries(hx.map(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}}>
<Component data={{pathname}} {...pageProps} />
<Component router={router} {...pageProps} />
</MDXProvider>;
}