mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +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
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import type {DocMetadata, LoadedContent} from '@docusaurus/plugin-content-docs';
|
||||
|
||||
function indexDocsBySource(content: LoadedContent): Map<string, DocMetadata> {
|
||||
const allDocs = content.loadedVersions.flatMap((v) => v.docs);
|
||||
return new Map(allDocs.map((doc) => [doc.source, doc]));
|
||||
}
|
||||
|
||||
// TODO this is bad, we should have a better way to do this (new lifecycle?)
|
||||
// The source to doc/permalink is a mutable map passed to the mdx loader
|
||||
// See https://github.com/facebook/docusaurus/pull/10457
|
||||
// See https://github.com/facebook/docusaurus/pull/10185
|
||||
export function createContentHelpers() {
|
||||
const sourceToDoc = new Map<string, DocMetadata>();
|
||||
const sourceToPermalink = new Map<string, string>();
|
||||
|
||||
// Mutable map update :/
|
||||
function updateContent(content: LoadedContent): void {
|
||||
sourceToDoc.clear();
|
||||
sourceToPermalink.clear();
|
||||
indexDocsBySource(content).forEach((value, key) => {
|
||||
sourceToDoc.set(key, value);
|
||||
sourceToPermalink.set(key, value.permalink);
|
||||
});
|
||||
}
|
||||
|
||||
return {updateContent, sourceToDoc, sourceToPermalink};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue