@docusaurus/plugin-content-docs 0.0.0-6064 → 0.0.0-6067

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
@@ -81,8 +63,7 @@ async function pluginContentDocs(context, options) {
81
63
  const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
82
64
  return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
83
65
  },
84
- // Assets allow to convert some relative images paths to
85
- // require(...) calls
66
+ // createAssets converts relative paths to require() calls
86
67
  createAssets: ({ frontMatter }) => ({
87
68
  image: frontMatter.image,
88
69
  }),
@@ -91,7 +72,7 @@ async function pluginContentDocs(context, options) {
91
72
  const version = (0, versions_1.getVersionFromSourceFilePath)(sourceFilePath, versionsMetadata);
92
73
  const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
93
74
  sourceFilePath,
94
- sourceToPermalink: sourceToPermalinkHelper.get(),
75
+ sourceToPermalink: contentHelpers.sourceToPermalink,
95
76
  siteDir,
96
77
  contentPaths: version,
97
78
  });
@@ -221,7 +202,7 @@ async function pluginContentDocs(context, options) {
221
202
  return (0, translations_1.translateLoadedContent)(content, translationFiles);
222
203
  },
223
204
  async contentLoaded({ content, actions }) {
224
- sourceToPermalinkHelper.update(content);
205
+ contentHelpers.updateContent(content);
225
206
  const versions = content.loadedVersions.map(versions_1.toFullVersion);
226
207
  await (0, routes_1.createAllRoutes)({
227
208
  baseUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-6064",
3
+ "version": "0.0.0-6067",
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-6064",
39
- "@docusaurus/logger": "0.0.0-6064",
40
- "@docusaurus/mdx-loader": "0.0.0-6064",
41
- "@docusaurus/module-type-aliases": "0.0.0-6064",
42
- "@docusaurus/theme-common": "0.0.0-6064",
43
- "@docusaurus/types": "0.0.0-6064",
44
- "@docusaurus/utils": "0.0.0-6064",
45
- "@docusaurus/utils-common": "0.0.0-6064",
46
- "@docusaurus/utils-validation": "0.0.0-6064",
38
+ "@docusaurus/core": "0.0.0-6067",
39
+ "@docusaurus/logger": "0.0.0-6067",
40
+ "@docusaurus/mdx-loader": "0.0.0-6067",
41
+ "@docusaurus/module-type-aliases": "0.0.0-6067",
42
+ "@docusaurus/theme-common": "0.0.0-6067",
43
+ "@docusaurus/types": "0.0.0-6067",
44
+ "@docusaurus/utils": "0.0.0-6067",
45
+ "@docusaurus/utils-common": "0.0.0-6067",
46
+ "@docusaurus/utils-validation": "0.0.0-6067",
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": "f9f463e54c7ff8013cb938f94857af8e4bff5a72"
70
+ "gitHead": "856911a5474e8e907f83438abe5c42d4793e06cb"
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 {
@@ -148,8 +125,7 @@ export default async function pluginContentDocs(
148
125
  const aliasedPath = aliasedSitePath(mdxPath, siteDir);
149
126
  return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
150
127
  },
151
- // Assets allow to convert some relative images paths to
152
- // require(...) calls
128
+ // createAssets converts relative paths to require() calls
153
129
  createAssets: ({frontMatter}: {frontMatter: DocFrontMatter}) => ({
154
130
  image: frontMatter.image,
155
131
  }),
@@ -161,7 +137,7 @@ export default async function pluginContentDocs(
161
137
  );
162
138
  const permalink = resolveMarkdownLinkPathname(linkPathname, {
163
139
  sourceFilePath,
164
- sourceToPermalink: sourceToPermalinkHelper.get(),
140
+ sourceToPermalink: contentHelpers.sourceToPermalink,
165
141
  siteDir,
166
142
  contentPaths: version,
167
143
  });
@@ -335,7 +311,7 @@ export default async function pluginContentDocs(
335
311
  },
336
312
 
337
313
  async contentLoaded({content, actions}) {
338
- sourceToPermalinkHelper.update(content);
314
+ contentHelpers.updateContent(content);
339
315
 
340
316
  const versions: FullVersion[] = content.loadedVersions.map(toFullVersion);
341
317