Feat/rehype-citation (#270)
* feat: add rehype-citation and upgrade to next 12.0.3 * docs: update docs
This commit is contained in:
26
lib/mdx.js
26
lib/mdx.js
@ -16,6 +16,7 @@ import remarkImgToJsx from './remark-img-to-jsx'
|
||||
import rehypeSlug from 'rehype-slug'
|
||||
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
|
||||
import rehypeKatex from 'rehype-katex'
|
||||
import rehypeCitation from 'rehype-citation'
|
||||
import rehypePrismPlus from 'rehype-prism-plus'
|
||||
|
||||
const root = process.cwd()
|
||||
@ -46,27 +47,18 @@ export async function getFileBySlug(type, slug) {
|
||||
|
||||
// https://github.com/kentcdodds/mdx-bundler#nextjs-esbuild-enoent
|
||||
if (process.platform === 'win32') {
|
||||
process.env.ESBUILD_BINARY_PATH = path.join(
|
||||
process.cwd(),
|
||||
'node_modules',
|
||||
'esbuild',
|
||||
'esbuild.exe'
|
||||
)
|
||||
process.env.ESBUILD_BINARY_PATH = path.join(root, 'node_modules', 'esbuild', 'esbuild.exe')
|
||||
} else {
|
||||
process.env.ESBUILD_BINARY_PATH = path.join(
|
||||
process.cwd(),
|
||||
'node_modules',
|
||||
'esbuild',
|
||||
'bin',
|
||||
'esbuild'
|
||||
)
|
||||
process.env.ESBUILD_BINARY_PATH = path.join(root, 'node_modules', 'esbuild', 'bin', 'esbuild')
|
||||
}
|
||||
|
||||
let toc = []
|
||||
|
||||
const { frontmatter, code } = await bundleMDX(source, {
|
||||
// Parsing frontmatter here to pass it in as options to rehype plugin
|
||||
const { data: frontmatter } = matter(source)
|
||||
const { code } = await bundleMDX(source, {
|
||||
// mdx imports can be automatically source from the components directory
|
||||
cwd: path.join(process.cwd(), 'components'),
|
||||
cwd: path.join(root, 'components'),
|
||||
xdmOptions(options) {
|
||||
// this is the recommended way to add custom remark/rehype plugins:
|
||||
// The syntax might look weird, but it protects you in case we add/remove
|
||||
@ -85,6 +77,10 @@ export async function getFileBySlug(type, slug) {
|
||||
rehypeSlug,
|
||||
rehypeAutolinkHeadings,
|
||||
rehypeKatex,
|
||||
[
|
||||
rehypeCitation,
|
||||
{ bibliography: frontmatter?.bibliography, path: path.join(root, 'data') },
|
||||
],
|
||||
[rehypePrismPlus, { ignoreMissing: true }],
|
||||
]
|
||||
return options
|
||||
|
Reference in New Issue
Block a user