feat: add MDXLayoutRenderer component

This commit is contained in:
Timothy Lin
2021-05-26 00:11:20 +08:00
parent 37527331d4
commit 8914349256
5 changed files with 23 additions and 11 deletions

View File

@ -1,11 +1,20 @@
import { MDXRemote } from 'next-mdx-remote'
import Image from 'next/image'
import CustomLink from './Link'
import Pre from './Pre'
const MDXComponents = {
export const MDXComponents = {
Image,
a: CustomLink,
pre: Pre,
}
export default MDXComponents
export const MDXLayoutRenderer = ({ layout, mdxSource, ...rest }) => {
const LayoutComponent = require(`../layouts/${layout}`).default
return (
<LayoutComponent {...rest}>
<MDXRemote {...mdxSource} components={MDXComponents} />
</LayoutComponent>
)
}