jonbio/components/MDXComponents.js

25 lines
702 B
JavaScript
Raw Normal View History

2021-07-04 15:21:11 +08:00
/* eslint-disable react/display-name */
2021-06-26 18:46:45 +08:00
import { useMemo } from 'react'
import { getMDXComponent } from 'mdx-bundler/client'
import Image from './Image'
2021-01-09 17:50:45 +08:00
import CustomLink from './Link'
2021-08-06 22:13:30 +08:00
import TOCInline from './TOCInline'
2021-05-20 23:57:13 +08:00
import Pre from './Pre'
2021-01-09 17:50:45 +08:00
2021-05-26 00:11:20 +08:00
export const MDXComponents = {
2021-01-09 17:50:45 +08:00
Image,
2021-08-06 22:13:30 +08:00
TOCInline,
2021-01-09 17:50:45 +08:00
a: CustomLink,
2021-05-20 23:57:13 +08:00
pre: Pre,
2021-07-04 15:21:11 +08:00
wrapper: ({ components, layout, ...rest }) => {
const Layout = require(`../layouts/${layout}`).default
return <Layout {...rest} />
},
2021-01-09 17:50:45 +08:00
}
2021-05-26 00:11:20 +08:00
export const MDXLayoutRenderer = ({ layout, mdxSource, ...rest }) => {
2021-07-04 15:21:11 +08:00
const MDXLayout = useMemo(() => getMDXComponent(mdxSource), [mdxSource])
2021-05-26 00:11:20 +08:00
2021-07-04 15:21:11 +08:00
return <MDXLayout layout={layout} components={MDXComponents} {...rest} />
2021-05-26 00:11:20 +08:00
}