mirror of
https://github.com/facebook/docusaurus.git
synced 2025-12-26 09:43:10 +00:00
Some checks failed
Argos CI / take-screenshots (push) Has been cancelled
Build Hash Router / Build Hash Router (push) Has been cancelled
Canary Release / Publish Canary (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Continuous Releases / Continuous Releases (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (18.0) (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (20) (push) Has been cancelled
E2E Tests / E2E — Yarn v1 (22) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (node-modules, -s) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (node-modules, -st) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (pnp, -s) (push) Has been cancelled
E2E Tests / E2E — Yarn Berry (pnp, -st) (push) Has been cancelled
E2E Tests / E2E — npm (push) Has been cancelled
E2E Tests / E2E — pnpm (push) Has been cancelled
* 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
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
/**
|
|
* 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};
|
|
}
|