Repository navigation
Expand file tree
/
Copy paththeme.tsx
More file actions
60 lines (51 loc) · 2.07 KB
/
Copy paththeme.tsx
File metadata and controls
60 lines (51 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { useEffect } from 'react';
import { MDXProvider } from '@mdx-js/react';
import highlightJs from 'highlight.js/lib/common';
import HtmlHead from './components/HtmlHead';
import AnchoredHeading from './components/AnchoredHeading';
import NodeApiVersionLinks from './components/Docs/NodeApiVersionLinks';
import { LayoutProvider } from './providers/layoutProvider';
import { useRouter } from './hooks/useRouter';
import type { FC, PropsWithChildren } from 'react';
import type { NextraThemeLayoutProps } from 'nextra';
import type { MDXComponents } from 'mdx/types';
import type { LegacyFrontMatter } from './types';
type LayoutProps = PropsWithChildren<{
pageOpts: NextraThemeLayoutProps['pageOpts'];
}>;
const mdxComponents: MDXComponents = {
NodeApiVersionLinks: NodeApiVersionLinks,
h1: props => <AnchoredHeading level={1} {...props} />,
h2: props => <AnchoredHeading level={2} {...props} />,
h3: props => <AnchoredHeading level={3} {...props} />,
h4: props => <AnchoredHeading level={4} {...props} />,
h5: props => <AnchoredHeading level={5} {...props} />,
h6: props => <AnchoredHeading level={6} {...props} />,
blockquote: ({ children }) => <div className="highlight-box">{children}</div>,
};
const Content: FC<LayoutProps> = ({ children }) => {
const { asPath } = useRouter();
// Re-highlights the pages on route change
useEffect(() => highlightJs.highlightAll(), [asPath]);
useEffect(() => window.startLegacyApp(), []);
return (
<MDXProvider components={mdxComponents} disableParentContext>
{children}
</MDXProvider>
);
};
// @TODO: Nextra should provide better customization to FrontMatter Props
type ThemeProps = {
pageOpts: Omit<NextraThemeLayoutProps['pageOpts'], 'frontMatter'> & {
frontMatter: LegacyFrontMatter;
};
} & NextraThemeLayoutProps;
const Theme: FC<ThemeProps> = ({ pageOpts, pageProps, children }) => (
<>
<HtmlHead frontMatter={pageOpts.frontMatter} />
<LayoutProvider pageOpts={pageOpts} pageProps={pageProps}>
<Content pageOpts={pageOpts}>{children}</Content>
</LayoutProvider>
</>
);
export default Theme;