mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-26 06:27:59 +02:00
fix(v2): move metadata export after compiling MDX to avoid weird MDX parsing error. (#2105)
* fix(v2): move metadata export to mdx-loader to prevent any weird mdx parsing * refactor * nits * nits * nits
This commit is contained in:
parent
1f0eb37e19
commit
ace93c5a14
7 changed files with 64 additions and 65 deletions
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
const {getOptions} = require('loader-utils');
|
||||
const {readFile} = require('fs-extra');
|
||||
const mdx = require('@mdx-js/mdx');
|
||||
const emoji = require('remark-emoji');
|
||||
const slug = require('remark-slug');
|
||||
|
@ -43,11 +44,25 @@ module.exports = async function(fileString) {
|
|||
return callback(err);
|
||||
}
|
||||
|
||||
let exportStr = `export const frontMatter = ${stringifyObject(data)};`;
|
||||
|
||||
// Read metadata for this MDX and export it
|
||||
if (options.metadataPath && typeof options.metadataPath === 'function') {
|
||||
const metadataPath = options.metadataPath(this.resourcePath);
|
||||
|
||||
if (metadataPath) {
|
||||
// Add as dependency of this loader result so that we can recompile if metadata is changed
|
||||
this.addDependency(metadataPath);
|
||||
const metadata = await readFile(metadataPath, 'utf8');
|
||||
exportStr += `\nexport const metadata = ${metadata};`;
|
||||
}
|
||||
}
|
||||
|
||||
const code = `
|
||||
import React from 'react';
|
||||
import { mdx } from '@mdx-js/react';
|
||||
|
||||
export const frontMatter = ${stringifyObject(data)};
|
||||
${exportStr}
|
||||
${result}
|
||||
`;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue