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:
Sébastien Lorber 2024-08-30 08:02:26 +02:00 committed by GitHub
parent 2aef92cb9e
commit a4329d3388
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 182 additions and 80 deletions

View file

@ -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});
},