jonbio/components/MDXComponents.js

23 lines
580 B
JavaScript
Raw Normal View History

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-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,
a: CustomLink,
2021-05-20 23:57:13 +08:00
pre: Pre,
2021-01-09 17:50:45 +08:00
}
2021-05-26 00:11:20 +08:00
export const MDXLayoutRenderer = ({ layout, mdxSource, ...rest }) => {
2021-06-26 18:46:45 +08:00
const MDXComponent = useMemo(() => getMDXComponent(mdxSource), [mdxSource])
2021-05-26 00:11:20 +08:00
const LayoutComponent = require(`../layouts/${layout}`).default
return (
<LayoutComponent {...rest}>
2021-06-26 18:46:45 +08:00
<MDXComponent components={MDXComponents} />
2021-05-26 00:11:20 +08:00
</LayoutComponent>
)
}