Add ability to load plugins

This commit is contained in:
Marcus Blättermann 2022-11-13 16:31:26 +01:00
parent 790e03f900
commit aea5496788
No known key found for this signature in database
GPG Key ID: A1E1F04008AC450D
3 changed files with 13 additions and 1 deletions

View File

@ -1,8 +1,11 @@
import MDX from '@next/mdx' import MDX from '@next/mdx'
import remarkPlugins from './plugins/index.mjs'
const withMDX = MDX({ const withMDX = MDX({
extension: /\.mdx?$/, extension: /\.mdx?$/,
options: { options: {
remarkPlugins,
providerImportSource: '@mdx-js/react', providerImportSource: '@mdx-js/react',
}, },
experimental: { experimental: {

View File

@ -4,6 +4,7 @@ import fs from 'fs'
import { MDXRemote, MDXRemoteSerializeResult } from 'next-mdx-remote' import { MDXRemote, MDXRemoteSerializeResult } from 'next-mdx-remote'
import path from 'path' import path from 'path'
import Layout from '../components/layout' import Layout from '../components/layout'
import remarkPlugins from '../plugins/index.mjs'
type PropsPage = { type PropsPage = {
mdx: MDXRemoteSerializeResult mdx: MDXRemoteSerializeResult
@ -43,7 +44,12 @@ export const getStaticProps: GetStaticProps<PropsPage, ParsedUrlQuery> = async (
slug: args.params.slug, slug: args.params.slug,
mdx: await serialize( mdx: await serialize(
fs.readFileSync(path.join('docs', args.params.slug + '.mdx'), 'utf-8'), fs.readFileSync(path.join('docs', args.params.slug + '.mdx'), 'utf-8'),
{ parseFrontmatter: true } {
parseFrontmatter: true,
mdxOptions: {
remarkPlugins,
},
}
), ),
}, },
} }

View File

@ -0,0 +1,3 @@
const remarkPlugins = []
export default remarkPlugins