mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-19 03:02:30 +02:00
refactor(mdx-loader): read metadata from memory (loaded content) instead of fs (#10457)
* mdx loader shouldn't read metadata from file system but from memory * comments * refactor: apply lint autofix * apply same for blog * apply same for blog * refactor: apply lint autofix * apply same for pages
This commit is contained in:
parent
2aef92cb9e
commit
a4329d3388
8 changed files with 182 additions and 80 deletions
|
@ -24,6 +24,7 @@ import {
|
|||
getContentPathList,
|
||||
loadPagesContent,
|
||||
} from './content';
|
||||
import {createContentHelpers} from './contentHelpers';
|
||||
import type {LoadContext, Plugin} from '@docusaurus/types';
|
||||
import type {
|
||||
PluginOptions,
|
||||
|
@ -46,6 +47,8 @@ export default async function pluginContentPages(
|
|||
);
|
||||
const dataDir = path.join(pluginDataDirRoot, options.id ?? DEFAULT_PLUGIN_ID);
|
||||
|
||||
const contentHelpers = createContentHelpers();
|
||||
|
||||
async function createPagesMDXLoaderRule(): Promise<RuleSetRule> {
|
||||
const {
|
||||
admonitions,
|
||||
|
@ -73,7 +76,15 @@ export default async function pluginContentPages(
|
|||
// Note that metadataPath must be the same/in-sync as
|
||||
// the path from createData for each MDX.
|
||||
const aliasedSource = aliasedSitePath(mdxPath, siteDir);
|
||||
return path.join(dataDir, `${docuHash(aliasedSource)}.json`);
|
||||
const metadataPath = path.join(
|
||||
dataDir,
|
||||
`${docuHash(aliasedSource)}.json`,
|
||||
);
|
||||
const metadataContent = contentHelpers.sourceToPage.get(aliasedSource);
|
||||
return {
|
||||
metadataPath,
|
||||
metadataContent,
|
||||
};
|
||||
},
|
||||
// Assets allow to convert some relative images paths to
|
||||
// require(...) calls
|
||||
|
@ -114,6 +125,7 @@ export default async function pluginContentPages(
|
|||
if (!content) {
|
||||
return;
|
||||
}
|
||||
contentHelpers.updateContent(content);
|
||||
await createAllRoutes({content, options, actions});
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue