@docusaurus/plugin-content-docs 0.0.0-6063 → 0.0.0-6065

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { DocMetadata, LoadedContent } from '@docusaurus/plugin-content-docs';
8
+ export declare function createContentHelpers(): {
9
+ updateContent: (content: LoadedContent) => void;
10
+ sourceToDoc: Map<string, DocMetadata>;
11
+ sourceToPermalink: Map<string, string>;
12
+ };
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createContentHelpers = createContentHelpers;
10
+ function indexDocsBySource(content) {
11
+ const allDocs = content.loadedVersions.flatMap((v) => v.docs);
12
+ return new Map(allDocs.map((doc) => [doc.source, doc]));
13
+ }
14
+ // TODO this is bad, we should have a better way to do this (new lifecycle?)
15
+ // The source to doc/permalink is a mutable map passed to the mdx loader
16
+ // See https://github.com/facebook/docusaurus/pull/10457
17
+ // See https://github.com/facebook/docusaurus/pull/10185
18
+ function createContentHelpers() {
19
+ const sourceToDoc = new Map();
20
+ const sourceToPermalink = new Map();
21
+ // Mutable map update :/
22
+ function updateContent(content) {
23
+ sourceToDoc.clear();
24
+ sourceToPermalink.clear();
25
+ indexDocsBySource(content).forEach((value, key) => {
26
+ sourceToDoc.set(key, value);
27
+ sourceToPermalink.set(key, value.permalink);
28
+ });
29
+ }
30
+ return { updateContent, sourceToDoc, sourceToPermalink };
31
+ }
package/lib/index.js CHANGED
@@ -25,25 +25,7 @@ const globalData_1 = require("./globalData");
25
25
  const translations_1 = require("./translations");
26
26
  const routes_1 = require("./routes");
27
27
  const utils_2 = require("./sidebars/utils");
28
- // TODO this is bad, we should have a better way to do this (new lifecycle?)
29
- // The source to permalink is currently a mutable map passed to the mdx loader
30
- // for link resolution
31
- // see https://github.com/facebook/docusaurus/pull/10185
32
- function createSourceToPermalinkHelper() {
33
- const sourceToPermalink = new Map();
34
- function computeSourceToPermalink(content) {
35
- const allDocs = content.loadedVersions.flatMap((v) => v.docs);
36
- return new Map(allDocs.map(({ source, permalink }) => [source, permalink]));
37
- }
38
- // Mutable map update :/
39
- function update(content) {
40
- sourceToPermalink.clear();
41
- computeSourceToPermalink(content).forEach((value, key) => {
42
- sourceToPermalink.set(key, value);
43
- });
44
- }
45
- return { get: () => sourceToPermalink, update };
46
- }
28
+ const contentHelpers_1 = require("./contentHelpers");
47
29
  async function pluginContentDocs(context, options) {
48
30
  const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
49
31
  // Mutate options to resolve sidebar path according to siteDir
@@ -58,7 +40,7 @@ async function pluginContentDocs(context, options) {
58
40
  const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
59
41
  // TODO env should be injected into all plugins
60
42
  const env = process.env.NODE_ENV;
61
- const sourceToPermalinkHelper = createSourceToPermalinkHelper();
43
+ const contentHelpers = (0, contentHelpers_1.createContentHelpers)();
62
44
  async function createDocsMDXLoaderRule() {
63
45
  const { rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
64
46
  const contentDirs = versionsMetadata
@@ -79,7 +61,12 @@ async function pluginContentDocs(context, options) {
79
61
  // Note that metadataPath must be the same/in-sync as
80
62
  // the path from createData for each MDX.
81
63
  const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
82
- return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
64
+ const metadataPath = path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
65
+ const metadataContent = contentHelpers.sourceToDoc.get(aliasedPath);
66
+ return {
67
+ metadataPath,
68
+ metadataContent,
69
+ };
83
70
  },
84
71
  // Assets allow to convert some relative images paths to
85
72
  // require(...) calls
@@ -91,7 +78,7 @@ async function pluginContentDocs(context, options) {
91
78
  const version = (0, versions_1.getVersionFromSourceFilePath)(sourceFilePath, versionsMetadata);
92
79
  const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
93
80
  sourceFilePath,
94
- sourceToPermalink: sourceToPermalinkHelper.get(),
81
+ sourceToPermalink: contentHelpers.sourceToPermalink,
95
82
  siteDir,
96
83
  contentPaths: version,
97
84
  });
@@ -221,7 +208,7 @@ async function pluginContentDocs(context, options) {
221
208
  return (0, translations_1.translateLoadedContent)(content, translationFiles);
222
209
  },
223
210
  async contentLoaded({ content, actions }) {
224
- sourceToPermalinkHelper.update(content);
211
+ contentHelpers.updateContent(content);
225
212
  const versions = content.loadedVersions.map(versions_1.toFullVersion);
226
213
  await (0, routes_1.createAllRoutes)({
227
214
  baseUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-6063",
3
+ "version": "0.0.0-6065",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -35,15 +35,15 @@
35
35
  },
36
36
  "license": "MIT",
37
37
  "dependencies": {
38
- "@docusaurus/core": "0.0.0-6063",
39
- "@docusaurus/logger": "0.0.0-6063",
40
- "@docusaurus/mdx-loader": "0.0.0-6063",
41
- "@docusaurus/module-type-aliases": "0.0.0-6063",
42
- "@docusaurus/theme-common": "0.0.0-6063",
43
- "@docusaurus/types": "0.0.0-6063",
44
- "@docusaurus/utils": "0.0.0-6063",
45
- "@docusaurus/utils-common": "0.0.0-6063",
46
- "@docusaurus/utils-validation": "0.0.0-6063",
38
+ "@docusaurus/core": "0.0.0-6065",
39
+ "@docusaurus/logger": "0.0.0-6065",
40
+ "@docusaurus/mdx-loader": "0.0.0-6065",
41
+ "@docusaurus/module-type-aliases": "0.0.0-6065",
42
+ "@docusaurus/theme-common": "0.0.0-6065",
43
+ "@docusaurus/types": "0.0.0-6065",
44
+ "@docusaurus/utils": "0.0.0-6065",
45
+ "@docusaurus/utils-common": "0.0.0-6065",
46
+ "@docusaurus/utils-validation": "0.0.0-6065",
47
47
  "@types/react-router-config": "^5.0.7",
48
48
  "combine-promises": "^1.1.0",
49
49
  "fs-extra": "^11.1.1",
@@ -67,5 +67,5 @@
67
67
  "engines": {
68
68
  "node": ">=18.0"
69
69
  },
70
- "gitHead": "d6fbbb85fcb98fd3bf658610f6d7345e5dad2530"
70
+ "gitHead": "6da713a524315a36515fc3e998ff1551bfa054d2"
71
71
  }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import type {DocMetadata, LoadedContent} from '@docusaurus/plugin-content-docs';
9
+
10
+ function indexDocsBySource(content: LoadedContent): Map<string, DocMetadata> {
11
+ const allDocs = content.loadedVersions.flatMap((v) => v.docs);
12
+ return new Map(allDocs.map((doc) => [doc.source, doc]));
13
+ }
14
+
15
+ // TODO this is bad, we should have a better way to do this (new lifecycle?)
16
+ // The source to doc/permalink is a mutable map passed to the mdx loader
17
+ // See https://github.com/facebook/docusaurus/pull/10457
18
+ // See https://github.com/facebook/docusaurus/pull/10185
19
+ export function createContentHelpers() {
20
+ const sourceToDoc = new Map<string, DocMetadata>();
21
+ const sourceToPermalink = new Map<string, string>();
22
+
23
+ // Mutable map update :/
24
+ function updateContent(content: LoadedContent): void {
25
+ sourceToDoc.clear();
26
+ sourceToPermalink.clear();
27
+ indexDocsBySource(content).forEach((value, key) => {
28
+ sourceToDoc.set(key, value);
29
+ sourceToPermalink.set(key, value.permalink);
30
+ });
31
+ }
32
+
33
+ return {updateContent, sourceToDoc, sourceToPermalink};
34
+ }
package/src/index.ts CHANGED
@@ -19,7 +19,6 @@ import {
19
19
  createSlugger,
20
20
  resolveMarkdownLinkPathname,
21
21
  DEFAULT_PLUGIN_ID,
22
- type SourceToPermalink,
23
22
  type TagsFile,
24
23
  } from '@docusaurus/utils';
25
24
  import {
@@ -54,6 +53,7 @@ import {
54
53
  import {createAllRoutes} from './routes';
55
54
  import {createSidebarsUtils} from './sidebars/utils';
56
55
 
56
+ import {createContentHelpers} from './contentHelpers';
57
57
  import type {
58
58
  PluginOptions,
59
59
  DocMetadataBase,
@@ -66,29 +66,6 @@ import type {LoadContext, Plugin} from '@docusaurus/types';
66
66
  import type {DocFile, FullVersion} from './types';
67
67
  import type {RuleSetRule} from 'webpack';
68
68
 
69
- // TODO this is bad, we should have a better way to do this (new lifecycle?)
70
- // The source to permalink is currently a mutable map passed to the mdx loader
71
- // for link resolution
72
- // see https://github.com/facebook/docusaurus/pull/10185
73
- function createSourceToPermalinkHelper() {
74
- const sourceToPermalink: SourceToPermalink = new Map();
75
-
76
- function computeSourceToPermalink(content: LoadedContent): SourceToPermalink {
77
- const allDocs = content.loadedVersions.flatMap((v) => v.docs);
78
- return new Map(allDocs.map(({source, permalink}) => [source, permalink]));
79
- }
80
-
81
- // Mutable map update :/
82
- function update(content: LoadedContent): void {
83
- sourceToPermalink.clear();
84
- computeSourceToPermalink(content).forEach((value, key) => {
85
- sourceToPermalink.set(key, value);
86
- });
87
- }
88
-
89
- return {get: () => sourceToPermalink, update};
90
- }
91
-
92
69
  export default async function pluginContentDocs(
93
70
  context: LoadContext,
94
71
  options: PluginOptions,
@@ -115,7 +92,7 @@ export default async function pluginContentDocs(
115
92
  // TODO env should be injected into all plugins
116
93
  const env = process.env.NODE_ENV as DocEnv;
117
94
 
118
- const sourceToPermalinkHelper = createSourceToPermalinkHelper();
95
+ const contentHelpers = createContentHelpers();
119
96
 
120
97
  async function createDocsMDXLoaderRule(): Promise<RuleSetRule> {
121
98
  const {
@@ -146,7 +123,15 @@ export default async function pluginContentDocs(
146
123
  // Note that metadataPath must be the same/in-sync as
147
124
  // the path from createData for each MDX.
148
125
  const aliasedPath = aliasedSitePath(mdxPath, siteDir);
149
- return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
126
+ const metadataPath = path.join(
127
+ dataDir,
128
+ `${docuHash(aliasedPath)}.json`,
129
+ );
130
+ const metadataContent = contentHelpers.sourceToDoc.get(aliasedPath);
131
+ return {
132
+ metadataPath,
133
+ metadataContent,
134
+ };
150
135
  },
151
136
  // Assets allow to convert some relative images paths to
152
137
  // require(...) calls
@@ -161,7 +146,7 @@ export default async function pluginContentDocs(
161
146
  );
162
147
  const permalink = resolveMarkdownLinkPathname(linkPathname, {
163
148
  sourceFilePath,
164
- sourceToPermalink: sourceToPermalinkHelper.get(),
149
+ sourceToPermalink: contentHelpers.sourceToPermalink,
165
150
  siteDir,
166
151
  contentPaths: version,
167
152
  });
@@ -335,7 +320,7 @@ export default async function pluginContentDocs(
335
320
  },
336
321
 
337
322
  async contentLoaded({content, actions}) {
338
- sourceToPermalinkHelper.update(content);
323
+ contentHelpers.updateContent(content);
339
324
 
340
325
  const versions: FullVersion[] = content.loadedVersions.map(toFullVersion);
341
326