-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(mdx-loader): read metadata from memory (loaded content) inst…
…ead 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
- Loading branch information
Showing
8 changed files
with
182 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/docusaurus-plugin-content-blog/src/contentHelpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* 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 {BlogContent, BlogPost} from '@docusaurus/plugin-content-blog'; | ||
|
||
function indexBlogPostsBySource(content: BlogContent): Map<string, BlogPost> { | ||
return new Map( | ||
content.blogPosts.map((blogPost) => [blogPost.metadata.source, blogPost]), | ||
); | ||
} | ||
|
||
// TODO this is bad, we should have a better way to do this (new lifecycle?) | ||
// The source to blog/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 sourceToBlogPost = new Map<string, BlogPost>(); | ||
const sourceToPermalink = new Map<string, string>(); | ||
|
||
// Mutable map update :/ | ||
function updateContent(content: BlogContent): void { | ||
sourceToBlogPost.clear(); | ||
sourceToPermalink.clear(); | ||
indexBlogPostsBySource(content).forEach((value, key) => { | ||
sourceToBlogPost.set(key, value); | ||
sourceToPermalink.set(key, value.metadata.permalink); | ||
}); | ||
} | ||
|
||
return {updateContent, sourceToBlogPost, sourceToPermalink}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/docusaurus-plugin-content-docs/src/contentHelpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/docusaurus-plugin-content-pages/src/contentHelpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* 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 {LoadedContent, Metadata} from '@docusaurus/plugin-content-pages'; | ||
|
||
function indexPagesBySource(content: LoadedContent): Map<string, Metadata> { | ||
return new Map(content.map((page) => [page.source, page])); | ||
} | ||
|
||
// TODO this is bad, we should have a better way to do this (new lifecycle?) | ||
// The source to page/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 sourceToPage = new Map<string, Metadata>(); | ||
// const sourceToPermalink = new Map<string, string>(); | ||
|
||
// Mutable map update :/ | ||
function updateContent(content: LoadedContent): void { | ||
sourceToPage.clear(); | ||
// sourceToPermalink.clear(); | ||
indexPagesBySource(content).forEach((value, key) => { | ||
sourceToPage.set(key, value); | ||
// sourceToPermalink.set(key, value.metadata.permalink); | ||
}); | ||
} | ||
|
||
return {updateContent, sourceToPage}; | ||
} |
Oops, something went wrong.