supMDX/pages/_app.tsx

21 lines
713 B
TypeScript
Raw Normal View History

2022-11-04 21:44:29 +09:00
import React from 'react';
import type {AppProps} from 'next/app';
import {MDXProvider} from '@mdx-js/react';
import {S} from '@/mdx';
import '../styles/index.sass';
// add anchor to all headings having id
const hx = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;
const extendedHx = Object.fromEntries(hx.map(H => [H,
({children, id, ...props}: React.ComponentProps<(typeof hx)[number]>) => <H id={id} {...props}>
2022-11-05 02:42:47 +09:00
{id && <a className="anchor" href={'#'+encodeURIComponent(id)} />}
2022-11-04 21:44:29 +09:00
{children}
</H>,
]));
2022-11-05 22:21:49 +09:00
export default function App({Component, pageProps, router}: AppProps) {
2022-11-04 21:44:29 +09:00
return <MDXProvider components={{S, ...extendedHx}}>
2022-11-05 22:21:49 +09:00
<Component router={router} {...pageProps} />
2022-11-04 21:44:29 +09:00
</MDXProvider>;
}