@docusaurus/plugin-content-docs 0.0.0-6058 → 0.0.0-6061

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.
Files changed (3) hide show
  1. package/lib/index.js +48 -55
  2. package/package.json +11 -11
  3. package/src/index.ts +69 -77
package/lib/index.js CHANGED
@@ -14,6 +14,7 @@ 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");
@@ -58,6 +59,51 @@ async function pluginContentDocs(context, options) {
58
59
  // TODO env should be injected into all plugins
59
60
  const env = process.env.NODE_ENV;
60
61
  const sourceToPermalinkHelper = createSourceToPermalinkHelper();
62
+ async function createDocsMDXLoaderRule() {
63
+ const { rehypePlugins, remarkPlugins, recmaPlugins, beforeDefaultRehypePlugins, beforeDefaultRemarkPlugins, } = options;
64
+ const contentDirs = versionsMetadata
65
+ .flatMap(utils_1.getContentPathList)
66
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
67
+ .map(utils_1.addTrailingPathSeparator);
68
+ const loaderOptions = {
69
+ admonitions: options.admonitions,
70
+ remarkPlugins,
71
+ rehypePlugins,
72
+ recmaPlugins,
73
+ beforeDefaultRehypePlugins,
74
+ beforeDefaultRemarkPlugins,
75
+ staticDirs: siteConfig.staticDirectories.map((dir) => path_1.default.resolve(siteDir, dir)),
76
+ siteDir,
77
+ isMDXPartial: (0, utils_1.createAbsoluteFilePathMatcher)(options.exclude, contentDirs),
78
+ metadataPath: (mdxPath) => {
79
+ // Note that metadataPath must be the same/in-sync as
80
+ // the path from createData for each MDX.
81
+ const aliasedPath = (0, utils_1.aliasedSitePath)(mdxPath, siteDir);
82
+ return path_1.default.join(dataDir, `${(0, utils_1.docuHash)(aliasedPath)}.json`);
83
+ },
84
+ // Assets allow to convert some relative images paths to
85
+ // require(...) calls
86
+ createAssets: ({ frontMatter }) => ({
87
+ image: frontMatter.image,
88
+ }),
89
+ markdownConfig: siteConfig.markdown,
90
+ resolveMarkdownLink: ({ linkPathname, sourceFilePath }) => {
91
+ const version = (0, versions_1.getVersionFromSourceFilePath)(sourceFilePath, versionsMetadata);
92
+ const permalink = (0, utils_1.resolveMarkdownLinkPathname)(linkPathname, {
93
+ sourceFilePath,
94
+ sourceToPermalink: sourceToPermalinkHelper.get(),
95
+ siteDir,
96
+ contentPaths: version,
97
+ });
98
+ if (permalink === null) {
99
+ 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}`;
100
+ }
101
+ return permalink;
102
+ },
103
+ };
104
+ return (0, mdx_loader_1.createMDXLoaderRule)({ include: contentDirs, options: loaderOptions });
105
+ }
106
+ const docsMDXLoaderRule = await createDocsMDXLoaderRule();
61
107
  return {
62
108
  name: 'docusaurus-plugin-content-docs',
63
109
  extendCli(cli) {
@@ -190,54 +236,7 @@ async function pluginContentDocs(context, options) {
190
236
  breadcrumbs: options.breadcrumbs,
191
237
  });
192
238
  },
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
- }
239
+ configureWebpack() {
241
240
  return {
242
241
  ignoreWarnings: [
243
242
  // Suppress warnings about non-existing of versions file.
@@ -250,13 +249,7 @@ async function pluginContentDocs(context, options) {
250
249
  },
251
250
  },
252
251
  module: {
253
- rules: [
254
- {
255
- test: /\.mdx?$/i,
256
- include: contentDirs,
257
- use: [createMDXLoader()],
258
- },
259
- ],
252
+ rules: [docsMDXLoaderRule],
260
253
  },
261
254
  };
262
255
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-6058",
3
+ "version": "0.0.0-6061",
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-6058",
39
- "@docusaurus/logger": "0.0.0-6058",
40
- "@docusaurus/mdx-loader": "0.0.0-6058",
41
- "@docusaurus/module-type-aliases": "0.0.0-6058",
42
- "@docusaurus/theme-common": "0.0.0-6058",
43
- "@docusaurus/types": "0.0.0-6058",
44
- "@docusaurus/utils": "0.0.0-6058",
45
- "@docusaurus/utils-common": "0.0.0-6058",
46
- "@docusaurus/utils-validation": "0.0.0-6058",
38
+ "@docusaurus/core": "0.0.0-6061",
39
+ "@docusaurus/logger": "0.0.0-6061",
40
+ "@docusaurus/mdx-loader": "0.0.0-6061",
41
+ "@docusaurus/module-type-aliases": "0.0.0-6061",
42
+ "@docusaurus/theme-common": "0.0.0-6061",
43
+ "@docusaurus/types": "0.0.0-6061",
44
+ "@docusaurus/utils": "0.0.0-6061",
45
+ "@docusaurus/utils-common": "0.0.0-6061",
46
+ "@docusaurus/utils-validation": "0.0.0-6061",
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": "1108fcbe4d387e2e3d0195d91157a968275970b3"
70
+ "gitHead": "3e2c2a06f0d0400f0adf145fd24ba37776c65dbf"
71
71
  }
package/src/index.ts CHANGED
@@ -26,6 +26,10 @@ import {
26
26
  getTagsFile,
27
27
  getTagsFilePathsToWatch,
28
28
  } from '@docusaurus/utils-validation';
29
+ import {
30
+ createMDXLoaderRule,
31
+ type Options as MDXLoaderOptions,
32
+ } from '@docusaurus/mdx-loader';
29
33
  import {loadSidebars, resolveSidebarPathOption} from './sidebars';
30
34
  import {CategoryMetadataFilenamePattern} from './sidebars/generator';
31
35
  import {
@@ -49,7 +53,6 @@ import {
49
53
  } from './translations';
50
54
  import {createAllRoutes} from './routes';
51
55
  import {createSidebarsUtils} from './sidebars/utils';
52
- import type {Options as MDXLoaderOptions} from '@docusaurus/mdx-loader';
53
56
 
54
57
  import type {
55
58
  PluginOptions,
@@ -61,7 +64,7 @@ import type {
61
64
  } from '@docusaurus/plugin-content-docs';
62
65
  import type {LoadContext, Plugin} from '@docusaurus/types';
63
66
  import type {DocFile, FullVersion} from './types';
64
- import type {RuleSetUseItem} from 'webpack';
67
+ import type {RuleSetRule} from 'webpack';
65
68
 
66
69
  // TODO this is bad, we should have a better way to do this (new lifecycle?)
67
70
  // The source to permalink is currently a mutable map passed to the mdx loader
@@ -114,6 +117,68 @@ export default async function pluginContentDocs(
114
117
 
115
118
  const sourceToPermalinkHelper = createSourceToPermalinkHelper();
116
119
 
120
+ async function createDocsMDXLoaderRule(): Promise<RuleSetRule> {
121
+ const {
122
+ rehypePlugins,
123
+ remarkPlugins,
124
+ recmaPlugins,
125
+ beforeDefaultRehypePlugins,
126
+ beforeDefaultRemarkPlugins,
127
+ } = options;
128
+ const contentDirs = versionsMetadata
129
+ .flatMap(getContentPathList)
130
+ // Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
131
+ .map(addTrailingPathSeparator);
132
+
133
+ const loaderOptions: MDXLoaderOptions = {
134
+ admonitions: options.admonitions,
135
+ remarkPlugins,
136
+ rehypePlugins,
137
+ recmaPlugins,
138
+ beforeDefaultRehypePlugins,
139
+ beforeDefaultRemarkPlugins,
140
+ staticDirs: siteConfig.staticDirectories.map((dir) =>
141
+ path.resolve(siteDir, dir),
142
+ ),
143
+ siteDir,
144
+ isMDXPartial: createAbsoluteFilePathMatcher(options.exclude, contentDirs),
145
+ metadataPath: (mdxPath: string) => {
146
+ // Note that metadataPath must be the same/in-sync as
147
+ // the path from createData for each MDX.
148
+ const aliasedPath = aliasedSitePath(mdxPath, siteDir);
149
+ return path.join(dataDir, `${docuHash(aliasedPath)}.json`);
150
+ },
151
+ // Assets allow to convert some relative images paths to
152
+ // require(...) calls
153
+ createAssets: ({frontMatter}: {frontMatter: DocFrontMatter}) => ({
154
+ image: frontMatter.image,
155
+ }),
156
+ markdownConfig: siteConfig.markdown,
157
+ resolveMarkdownLink: ({linkPathname, sourceFilePath}) => {
158
+ const version = getVersionFromSourceFilePath(
159
+ sourceFilePath,
160
+ versionsMetadata,
161
+ );
162
+ const permalink = resolveMarkdownLinkPathname(linkPathname, {
163
+ sourceFilePath,
164
+ sourceToPermalink: sourceToPermalinkHelper.get(),
165
+ siteDir,
166
+ contentPaths: version,
167
+ });
168
+ if (permalink === null) {
169
+ logger.report(
170
+ siteConfig.onBrokenMarkdownLinks,
171
+ )`Docs markdown link couldn't be resolved: (url=${linkPathname}) in source file path=${sourceFilePath} for version number=${version.versionName}`;
172
+ }
173
+ return permalink;
174
+ },
175
+ };
176
+
177
+ return createMDXLoaderRule({include: contentDirs, options: loaderOptions});
178
+ }
179
+
180
+ const docsMDXLoaderRule = await createDocsMDXLoaderRule();
181
+
117
182
  return {
118
183
  name: 'docusaurus-plugin-content-docs',
119
184
 
@@ -289,74 +354,7 @@ export default async function pluginContentDocs(
289
354
  });
290
355
  },
291
356
 
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
-
357
+ configureWebpack() {
360
358
  return {
361
359
  ignoreWarnings: [
362
360
  // Suppress warnings about non-existing of versions file.
@@ -370,13 +368,7 @@ export default async function pluginContentDocs(
370
368
  },
371
369
  },
372
370
  module: {
373
- rules: [
374
- {
375
- test: /\.mdx?$/i,
376
- include: contentDirs,
377
- use: [createMDXLoader()],
378
- },
379
- ],
371
+ rules: [docsMDXLoaderRule],
380
372
  },
381
373
  };
382
374
  },