@docusaurus/plugin-content-docs 3.5.1 → 3.5.2-canary-6122

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.
package/lib/cli.d.ts CHANGED
@@ -6,4 +6,8 @@
6
6
  */
7
7
  import type { PluginOptions } from '@docusaurus/plugin-content-docs';
8
8
  import type { LoadContext } from '@docusaurus/types';
9
- export declare function cliDocsVersionCommand(version: unknown, { id: pluginId, path: docsPath, sidebarPath }: PluginOptions, { siteDir, i18n }: LoadContext): Promise<void>;
9
+ declare function cliDocsVersionCommand(version: unknown, { id: pluginId, path: docsPath, sidebarPath }: PluginOptions, { siteDir, i18n }: LoadContext): Promise<void>;
10
+ declare const _default: {
11
+ cliDocsVersionCommand: typeof cliDocsVersionCommand;
12
+ };
13
+ export default _default;
package/lib/cli.js CHANGED
@@ -6,7 +6,6 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.cliDocsVersionCommand = cliDocsVersionCommand;
10
9
  const tslib_1 = require("tslib");
11
10
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
11
  const path_1 = tslib_1.__importDefault(require("path"));
@@ -89,3 +88,16 @@ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, si
89
88
  await fs_extra_1.default.outputFile((0, files_1.getVersionsFilePath)(siteDir, pluginId), `${JSON.stringify(versions, null, 2)}\n`);
90
89
  logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
91
90
  }
91
+ // TODO try to remove this workaround
92
+ // Why use a default export instead of named exports here?
93
+ // This is only to make Jest mocking happy
94
+ // After upgrading Jest/SWC we got this weird mocking error in extendCli tests
95
+ // "spyOn: Cannot redefine property cliDocsVersionCommand"
96
+ // I tried various workarounds, and it's the only one that worked :/
97
+ // See also:
98
+ // - https://pyk.sh/fixing-typeerror-cannot-redefine-property-x-error-in-jest-tests#heading-solution-2-using-barrel-imports
99
+ // - https://github.com/aelbore/esbuild-jest/issues/26
100
+ // - https://stackoverflow.com/questions/67872622/jest-spyon-not-working-on-index-file-cannot-redefine-property/69951703#69951703
101
+ exports.default = {
102
+ cliDocsVersionCommand,
103
+ };
@@ -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
@@ -14,35 +14,18 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
15
  const utils_1 = require("@docusaurus/utils");
16
16
  const utils_validation_1 = require("@docusaurus/utils-validation");
17
+ const mdx_loader_1 = require("@docusaurus/mdx-loader");
17
18
  const sidebars_1 = require("./sidebars");
18
19
  const generator_1 = require("./sidebars/generator");
19
20
  const docs_1 = require("./docs");
20
21
  const versions_1 = require("./versions");
21
- const cli_1 = require("./cli");
22
+ const cli_1 = tslib_1.__importDefault(require("./cli"));
22
23
  const constants_1 = require("./constants");
23
24
  const globalData_1 = require("./globalData");
24
25
  const translations_1 = require("./translations");
25
26
  const routes_1 = require("./routes");
26
27
  const utils_2 = require("./sidebars/utils");
27
- // TODO this is bad, we should have a better way to do this (new lifecycle?)
28
- // The source to permalink is currently a mutable map passed to the mdx loader
29
- // for link resolution
30
- // see https://github.com/facebook/docusaurus/pull/10185
31
- function createSourceToPermalinkHelper() {
32
- const sourceToPermalink = new Map();
33
- function computeSourceToPermalink(content) {
34
- const allDocs = content.loadedVersions.flatMap((v) => v.docs);
35
- return new Map(allDocs.map(({ source, permalink }) => [source, permalink]));
36
- }
37
- // Mutable map update :/
38
- function update(content) {
39
- sourceToPermalink.clear();
40
- computeSourceToPermalink(content).forEach((value, key) => {
41
- sourceToPermalink.set(key, value);
42
- });
43
- }
44
- return { get: () => sourceToPermalink, update };
45
- }
28
+ const contentHelpers_1 = require("./contentHelpers");
46
29
  async function pluginContentDocs(context, options) {
47
30
  const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
48
31
  // Mutate options to resolve sidebar path according to siteDir
@@ -57,7 +40,54 @@ async function pluginContentDocs(context, options) {
57
40
  const aliasedSource = (source) => `~docs/${(0, utils_1.posixPath)(path_1.default.relative(pluginDataDirRoot, source))}`;
58
41
  // TODO env should be injected into all plugins
59
42
  const env = process.env.NODE_ENV;
60
- const sourceToPermalinkHelper = createSourceToPermalinkHelper();
43
+ const contentHelpers = (0, contentHelpers_1.createContentHelpers)();
44
+ async function createDocsMDXLoaderRule() {
45
+ const { rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
46
+ const contentDirs = versionsMetadata
47
+ .flatMap(utils_1.getContentPathList)
48
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
49
+ .map(utils_1.addTrailingPathSeparator);
50
+ return (0, mdx_loader_1.createMDXLoaderRule)({
51
+ include: contentDirs,
52
+ options: {
53
+ useCrossCompilerCache: siteConfig.future.experimental_faster.mdxCrossCompilerCache,
54
+ admonitions: options.admonitions,
55
+ remarkPlugins,
56
+ rehypePlugins,
57
+ recmaPlugins,
58
+ beforeDefaultRehypePlugins,
59
+ beforeDefaultRemarkPlugins,
60
+ staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
61
+ siteDir,
62
+ isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
63
+ metadataPath: (mdxPath) => {
64
+ // Note that metadataPath must be the same/in-sync as
65
+ // the path from createData for each MDX.
66
+ const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
67
+ return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
68
+ },
69
+ // createAssets converts relative paths to require() calls
70
+ createAssets: ({ frontMatter }) => ({
71
+ image: frontMatter.image,
72
+ }),
73
+ markdownConfig: siteConfig.markdown,
74
+ resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
75
+ const version = (0, versions_1.getVersionFromSourceFilePath)(sourceFilePath, versionsMetadata);
76
+ const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
77
+ sourceFilePath,
78
+ sourceToPermalink: contentHelpers.sourceToPermalink,
79
+ siteDir,
80
+ contentPaths: version,
81
+ });
82
+ if (permalink === null) {
83
+ logger_1.default.report(siteConfig.onBrokenMarkdownLinks) `Docs markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath} for version number=${version.versionName}`;
84
+ }
85
+ return permalink;
86
+ },
87
+ },
88
+ });
89
+ }
90
+ const docsMDXLoaderRule = await createDocsMDXLoaderRule();
61
91
  return {
62
92
  name: 'docusaurus-plugin-content-docs',
63
93
  extendCli(cli) {
@@ -74,7 +104,7 @@ async function pluginContentDocs(context, options) {
74
104
  .command(command)
75
105
  .arguments('<version>')
76
106
  .description(commandDescription)
77
- .action((version) => (0, cli_1.cliDocsVersionCommand)(version, options, context));
107
+ .action((version) => cli_1.default.cliDocsVersionCommand(version, options, context));
78
108
  },
79
109
  getTranslationFiles({ content }) {
80
110
  return (0, translations_1.getLoadedContentTranslationFiles)(content);
@@ -175,7 +205,7 @@ async function pluginContentDocs(context, options) {
175
205
  return (0, translations_1.translateLoadedContent)(content, translationFiles);
176
206
  },
177
207
  async contentLoaded({ content, actions }) {
178
- sourceToPermalinkHelper.update(content);
208
+ contentHelpers.updateContent(content);
179
209
  const versions = content.loadedVersions.map(versions_1.toFullVersion);
180
210
  await (0, routes_1.createAllRoutes)({
181
211
  baseUrl,
@@ -190,54 +220,7 @@ async function pluginContentDocs(context, options) {
190
220
  breadcrumbs: options.breadcrumbs,
191
221
  });
192
222
  },
193
- configureWebpack(_config, isServer, utils, content) {
194
- const { rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
195
- const contentDirs = versionsMetadata
196
- .flatMap(utils_1.getContentPathList)
197
- // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
198
- .map(utils_1.addTrailingPathSeparator);
199
- function createMDXLoader() {
200
- const loaderOptions = {
201
- admonitions: options.admonitions,
202
- remarkPlugins,
203
- rehypePlugins,
204
- recmaPlugins,
205
- beforeDefaultRehypePlugins,
206
- beforeDefaultRemarkPlugins,
207
- staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
208
- siteDir,
209
- isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
210
- metadataPath: (mdxPath) => {
211
- // Note that metadataPath must be the same/in-sync as
212
- // the path from createData for each MDX.
213
- const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
214
- return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
215
- },
216
- // Assets allow to convert some relative images paths to
217
- // require(...) calls
218
- createAssets: ({ frontMatter }) => ({
219
- image: frontMatter.image,
220
- }),
221
- markdownConfig: siteConfig.markdown,
222
- resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
223
- const version = (0, versions_1.getVersionFromSourceFilePath)(sourceFilePath, content.loadedVersions);
224
- const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
225
- sourceFilePath,
226
- sourceToPermalink: sourceToPermalinkHelper.get(),
227
- siteDir,
228
- contentPaths: version,
229
- });
230
- if (permalink === null) {
231
- logger_1.default.report(siteConfig.onBrokenMarkdownLinks) `Docs markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath} for version number=${version.versionName}`;
232
- }
233
- return permalink;
234
- },
235
- };
236
- return {
237
- loader: require.resolve('@docusaurus/mdx-loader'),
238
- options: loaderOptions,
239
- };
240
- }
223
+ configureWebpack() {
241
224
  return {
242
225
  ignoreWarnings: [
243
226
  // Suppress warnings about non-existing of versions file.
@@ -250,13 +233,7 @@ async function pluginContentDocs(context, options) {
250
233
  },
251
234
  },
252
235
  module: {
253
- rules: [
254
- {
255
- test: /\.mdx?$/i,
256
- include: contentDirs,
257
- use: [createMDXLoader()],
258
- },
259
- ],
236
+ rules: [docsMDXLoaderRule],
260
237
  },
261
238
  };
262
239
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "3.5.1",
3
+ "version": "3.5.2-canary-6122",
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": "3.5.1",
39
- "@docusaurus/logger": "3.5.1",
40
- "@docusaurus/mdx-loader": "3.5.1",
41
- "@docusaurus/module-type-aliases": "3.5.1",
42
- "@docusaurus/theme-common": "3.5.1",
43
- "@docusaurus/types": "3.5.1",
44
- "@docusaurus/utils": "3.5.1",
45
- "@docusaurus/utils-common": "3.5.1",
46
- "@docusaurus/utils-validation": "3.5.1",
38
+ "@docusaurus/core": "3.5.2-canary-6122",
39
+ "@docusaurus/logger": "3.5.2-canary-6122",
40
+ "@docusaurus/mdx-loader": "3.5.2-canary-6122",
41
+ "@docusaurus/module-type-aliases": "3.5.2-canary-6122",
42
+ "@docusaurus/theme-common": "3.5.2-canary-6122",
43
+ "@docusaurus/types": "3.5.2-canary-6122",
44
+ "@docusaurus/utils": "3.5.2-canary-6122",
45
+ "@docusaurus/utils-common": "3.5.2-canary-6122",
46
+ "@docusaurus/utils-validation": "3.5.2-canary-6122",
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": "5acbc57bd62f3f808ef72007cd67d4c410d13829"
70
+ "gitHead": "13455a98d6f59bad263db5629d67cbed578c4250"
71
71
  }
package/src/cli.ts CHANGED
@@ -53,7 +53,7 @@ async function createVersionedSidebarFile({
53
53
  }
54
54
 
55
55
  // Tests depend on non-default export for mocking.
56
- export async function cliDocsVersionCommand(
56
+ async function cliDocsVersionCommand(
57
57
  version: unknown,
58
58
  {id: pluginId, path: docsPath, sidebarPath}: PluginOptions,
59
59
  {siteDir, i18n}: LoadContext,
@@ -142,3 +142,17 @@ export async function cliDocsVersionCommand(
142
142
 
143
143
  logger.success`name=${pluginIdLogPrefix}: version name=${version} created!`;
144
144
  }
145
+
146
+ // TODO try to remove this workaround
147
+ // Why use a default export instead of named exports here?
148
+ // This is only to make Jest mocking happy
149
+ // After upgrading Jest/SWC we got this weird mocking error in extendCli tests
150
+ // "spyOn: Cannot redefine property cliDocsVersionCommand"
151
+ // I tried various workarounds, and it's the only one that worked :/
152
+ // See also:
153
+ // - https://pyk.sh/fixing-typeerror-cannot-redefine-property-x-error-in-jest-tests#heading-solution-2-using-barrel-imports
154
+ // - https://github.com/aelbore/esbuild-jest/issues/26
155
+ // - https://stackoverflow.com/questions/67872622/jest-spyon-not-working-on-index-file-cannot-redefine-property/69951703#69951703
156
+ export default {
157
+ cliDocsVersionCommand,
158
+ };
@@ -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,13 +19,13 @@ 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 {
26
25
  getTagsFile,
27
26
  getTagsFilePathsToWatch,
28
27
  } from '@docusaurus/utils-validation';
28
+ import {createMDXLoaderRule} from '@docusaurus/mdx-loader';
29
29
  import {loadSidebars, resolveSidebarPathOption} from './sidebars';
30
30
  import {CategoryMetadataFilenamePattern} from './sidebars/generator';
31
31
  import {
@@ -40,7 +40,7 @@ import {
40
40
  readVersionsMetadata,
41
41
  toFullVersion,
42
42
  } from './versions';
43
- import {cliDocsVersionCommand} from './cli';
43
+ import cliDocs from './cli';
44
44
  import {VERSIONS_JSON_FILE} from './constants';
45
45
  import {toGlobalDataVersion} from './globalData';
46
46
  import {
@@ -49,8 +49,8 @@ import {
49
49
  } from './translations';
50
50
  import {createAllRoutes} from './routes';
51
51
  import {createSidebarsUtils} from './sidebars/utils';
52
- import type {Options as MDXLoaderOptions} from '@docusaurus/mdx-loader';
53
52
 
53
+ import {createContentHelpers} from './contentHelpers';
54
54
  import type {
55
55
  PluginOptions,
56
56
  DocMetadataBase,
@@ -61,30 +61,7 @@ import type {
61
61
  } from '@docusaurus/plugin-content-docs';
62
62
  import type {LoadContext, Plugin} from '@docusaurus/types';
63
63
  import type {DocFile, FullVersion} from './types';
64
- import type {RuleSetUseItem} from 'webpack';
65
-
66
- // TODO this is bad, we should have a better way to do this (new lifecycle?)
67
- // The source to permalink is currently a mutable map passed to the mdx loader
68
- // for link resolution
69
- // see https://github.com/facebook/docusaurus/pull/10185
70
- function createSourceToPermalinkHelper() {
71
- const sourceToPermalink: SourceToPermalink = new Map();
72
-
73
- function computeSourceToPermalink(content: LoadedContent): SourceToPermalink {
74
- const allDocs = content.loadedVersions.flatMap((v) => v.docs);
75
- return new Map(allDocs.map(({source, permalink}) => [source, permalink]));
76
- }
77
-
78
- // Mutable map update :/
79
- function update(content: LoadedContent): void {
80
- sourceToPermalink.clear();
81
- computeSourceToPermalink(content).forEach((value, key) => {
82
- sourceToPermalink.set(key, value);
83
- });
84
- }
85
-
86
- return {get: () => sourceToPermalink, update};
87
- }
64
+ import type {RuleSetRule} from 'webpack';
88
65
 
89
66
  export default async function pluginContentDocs(
90
67
  context: LoadContext,
@@ -112,7 +89,74 @@ export default async function pluginContentDocs(
112
89
  // TODO env should be injected into all plugins
113
90
  const env = process.env.NODE_ENV as DocEnv;
114
91
 
115
- const sourceToPermalinkHelper = createSourceToPermalinkHelper();
92
+ const contentHelpers = createContentHelpers();
93
+
94
+ async function createDocsMDXLoaderRule(): Promise<RuleSetRule> {
95
+ const {
96
+ rehypePlugins,
97
+ remarkPlugins,
98
+ recmaPlugins,
99
+ beforeDefaultRehypePlugins,
100
+ beforeDefaultRemarkPlugins,
101
+ } = options;
102
+ const contentDirs = versionsMetadata
103
+ .flatMap(getContentPathList)
104
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
105
+ .map(addTrailingPathSeparator);
106
+
107
+ return createMDXLoaderRule({
108
+ include: contentDirs,
109
+ options: {
110
+ useCrossCompilerCache:
111
+ siteConfig.future.experimental_faster.mdxCrossCompilerCache,
112
+ admonitions: options.admonitions,
113
+ remarkPlugins,
114
+ rehypePlugins,
115
+ recmaPlugins,
116
+ beforeDefaultRehypePlugins,
117
+ beforeDefaultRemarkPlugins,
118
+ staticDirs: siteConfig.staticDirectories.map((dir) =>
119
+ path.resolve(siteDir, dir),
120
+ ),
121
+ siteDir,
122
+ isMDXPartial: createAbsoluteFilePathMatcher(
123
+ options.exclude,
124
+ contentDirs,
125
+ ),
126
+ metadataPath: (mdxPath: string) => {
127
+ // Note that metadataPath must be the same/in-sync as
128
+ // the path from createData for each MDX.
129
+ const aliasedPath = aliasedSitePath(mdxPath, siteDir);
130
+ return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
131
+ },
132
+ // createAssets converts relative paths to require() calls
133
+ createAssets: ({frontMatter}: {frontMatter: DocFrontMatter}) => ({
134
+ image: frontMatter.image,
135
+ }),
136
+ markdownConfig: siteConfig.markdown,
137
+ resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
138
+ const version = getVersionFromSourceFilePath(
139
+ sourceFilePath,
140
+ versionsMetadata,
141
+ );
142
+ const permalink = resolveMarkdownLinkPathname(linkPathname, {
143
+ sourceFilePath,
144
+ sourceToPermalink: contentHelpers.sourceToPermalink,
145
+ siteDir,
146
+ contentPaths: version,
147
+ });
148
+ if (permalink === null) {
149
+ logger.report(
150
+ siteConfig.onBrokenMarkdownLinks,
151
+ )`Docs markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath} for version number=${version.versionName}`;
152
+ }
153
+ return permalink;
154
+ },
155
+ },
156
+ });
157
+ }
158
+
159
+ const docsMDXLoaderRule = await createDocsMDXLoaderRule();
116
160
 
117
161
  return {
118
162
  name: 'docusaurus-plugin-content-docs',
@@ -134,7 +178,7 @@ export default async function pluginContentDocs(
134
178
  .arguments('<version>')
135
179
  .description(commandDescription)
136
180
  .action((version: unknown) =>
137
- cliDocsVersionCommand(version, options, context),
181
+ cliDocs.cliDocsVersionCommand(version, options, context),
138
182
  );
139
183
  },
140
184
 
@@ -270,7 +314,7 @@ export default async function pluginContentDocs(
270
314
  },
271
315
 
272
316
  async contentLoaded({content, actions}) {
273
- sourceToPermalinkHelper.update(content);
317
+ contentHelpers.updateContent(content);
274
318
 
275
319
  const versions: FullVersion[] = content.loadedVersions.map(toFullVersion);
276
320
 
@@ -289,74 +333,7 @@ export default async function pluginContentDocs(
289
333
  });
290
334
  },
291
335
 
292
- configureWebpack(_config, isServer, utils, content) {
293
- const {
294
- rehypePlugins,
295
- remarkPlugins,
296
- recmaPlugins,
297
- beforeDefaultRehypePlugins,
298
- beforeDefaultRemarkPlugins,
299
- } = options;
300
-
301
- const contentDirs = versionsMetadata
302
- .flatMap(getContentPathList)
303
- // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
304
- .map(addTrailingPathSeparator);
305
-
306
- function createMDXLoader(): RuleSetUseItem {
307
- const loaderOptions: MDXLoaderOptions = {
308
- admonitions: options.admonitions,
309
- remarkPlugins,
310
- rehypePlugins,
311
- recmaPlugins,
312
- beforeDefaultRehypePlugins,
313
- beforeDefaultRemarkPlugins,
314
- staticDirs: siteConfig.staticDirectories.map((dir) =>
315
- path.resolve(siteDir, dir),
316
- ),
317
- siteDir,
318
- isMDXPartial: createAbsoluteFilePathMatcher(
319
- options.exclude,
320
- contentDirs,
321
- ),
322
- metadataPath: (mdxPath: string) => {
323
- // Note that metadataPath must be the same/in-sync as
324
- // the path from createData for each MDX.
325
- const aliasedPath = aliasedSitePath(mdxPath, siteDir);
326
- return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
327
- },
328
- // Assets allow to convert some relative images paths to
329
- // require(...) calls
330
- createAssets: ({frontMatter}: {frontMatter: DocFrontMatter}) => ({
331
- image: frontMatter.image,
332
- }),
333
- markdownConfig: siteConfig.markdown,
334
- resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
335
- const version = getVersionFromSourceFilePath(
336
- sourceFilePath,
337
- content.loadedVersions,
338
- );
339
- const permalink = resolveMarkdownLinkPathname(linkPathname, {
340
- sourceFilePath,
341
- sourceToPermalink: sourceToPermalinkHelper.get(),
342
- siteDir,
343
- contentPaths: version,
344
- });
345
- if (permalink === null) {
346
- logger.report(
347
- siteConfig.onBrokenMarkdownLinks,
348
- )`Docs markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath} for version number=${version.versionName}`;
349
- }
350
- return permalink;
351
- },
352
- };
353
-
354
- return {
355
- loader: require.resolve('@docusaurus/mdx-loader'),
356
- options: loaderOptions,
357
- };
358
- }
359
-
336
+ configureWebpack() {
360
337
  return {
361
338
  ignoreWarnings: [
362
339
  // Suppress warnings about non-existing of versions file.
@@ -370,13 +347,7 @@ export default async function pluginContentDocs(
370
347
  },
371
348
  },
372
349
  module: {
373
- rules: [
374
- {
375
- test: /\.mdx?$/i,
376
- include: contentDirs,
377
- use: [createMDXLoader()],
378
- },
379
- ],
350
+ rules: [docsMDXLoaderRule],
380
351
  },
381
352
  };
382
353
  },