@docusaurus/plugin-content-docs 2.0.0-beta.18 → 2.0.0-beta.19

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 (76) hide show
  1. package/lib/categoryGeneratedIndex.d.ts +1 -1
  2. package/lib/categoryGeneratedIndex.js +4 -2
  3. package/lib/cli.d.ts +3 -2
  4. package/lib/cli.js +45 -35
  5. package/lib/client/docsClientUtils.d.ts +6 -5
  6. package/lib/client/docsClientUtils.js +8 -10
  7. package/lib/client/index.d.ts +9 -8
  8. package/lib/client/index.js +30 -33
  9. package/lib/constants.d.ts +4 -0
  10. package/lib/constants.js +4 -1
  11. package/lib/docs.d.ts +5 -3
  12. package/lib/docs.js +18 -13
  13. package/lib/frontMatter.d.ts +1 -1
  14. package/lib/frontMatter.js +3 -0
  15. package/lib/globalData.d.ts +2 -2
  16. package/lib/globalData.js +6 -6
  17. package/lib/index.d.ts +1 -2
  18. package/lib/index.js +31 -23
  19. package/lib/markdown/linkify.js +1 -2
  20. package/lib/props.d.ts +3 -3
  21. package/lib/props.js +7 -6
  22. package/lib/routes.d.ts +5 -4
  23. package/lib/routes.js +9 -23
  24. package/lib/server-export.d.ts +2 -1
  25. package/lib/server-export.js +3 -4
  26. package/lib/sidebars/generator.js +3 -3
  27. package/lib/sidebars/index.js +0 -2
  28. package/lib/sidebars/normalization.js +1 -1
  29. package/lib/sidebars/postProcessor.js +2 -2
  30. package/lib/sidebars/processor.js +14 -3
  31. package/lib/sidebars/types.d.ts +18 -14
  32. package/lib/sidebars/utils.d.ts +3 -3
  33. package/lib/slug.d.ts +1 -2
  34. package/lib/tags.d.ts +2 -1
  35. package/lib/tags.js +1 -1
  36. package/lib/translations.d.ts +3 -3
  37. package/lib/translations.js +3 -53
  38. package/lib/types.d.ts +8 -96
  39. package/lib/versions/files.d.ts +44 -0
  40. package/lib/versions/files.js +142 -0
  41. package/lib/versions/index.d.ts +36 -0
  42. package/lib/versions/index.js +155 -0
  43. package/lib/versions/validation.d.ts +17 -0
  44. package/lib/versions/validation.js +71 -0
  45. package/package.json +14 -12
  46. package/src/categoryGeneratedIndex.ts +8 -3
  47. package/src/cli.ts +62 -65
  48. package/src/client/docsClientUtils.ts +11 -13
  49. package/src/client/index.ts +41 -42
  50. package/src/constants.ts +4 -2
  51. package/src/docs.ts +41 -26
  52. package/src/frontMatter.ts +6 -3
  53. package/src/globalData.ts +10 -10
  54. package/src/index.ts +44 -38
  55. package/src/markdown/linkify.ts +2 -3
  56. package/src/plugin-content-docs.d.ts +447 -113
  57. package/src/props.ts +12 -9
  58. package/src/routes.ts +13 -39
  59. package/src/server-export.ts +1 -3
  60. package/src/sidebars/generator.ts +4 -4
  61. package/src/sidebars/index.ts +0 -2
  62. package/src/sidebars/normalization.ts +1 -1
  63. package/src/sidebars/postProcessor.ts +2 -2
  64. package/src/sidebars/processor.ts +24 -5
  65. package/src/sidebars/types.ts +20 -19
  66. package/src/sidebars/utils.ts +6 -3
  67. package/src/slug.ts +4 -2
  68. package/src/tags.ts +3 -2
  69. package/src/translations.ts +10 -61
  70. package/src/types.ts +13 -106
  71. package/src/versions/files.ts +220 -0
  72. package/src/versions/index.ts +247 -0
  73. package/src/versions/validation.ts +113 -0
  74. package/lib/versions.d.ts +0 -41
  75. package/lib/versions.js +0 -324
  76. package/src/versions.ts +0 -606
package/src/index.ts CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  normalizeUrl,
12
12
  docuHash,
13
13
  aliasedSitePath,
14
+ getContentPathList,
14
15
  reportMessage,
15
16
  posixPath,
16
17
  addTrailingPathSeparator,
@@ -19,32 +20,24 @@ import {
19
20
  DEFAULT_PLUGIN_ID,
20
21
  } from '@docusaurus/utils';
21
22
  import type {LoadContext, Plugin} from '@docusaurus/types';
22
- import {loadSidebars} from './sidebars';
23
+ import {loadSidebars, resolveSidebarPathOption} from './sidebars';
23
24
  import {CategoryMetadataFilenamePattern} from './sidebars/generator';
24
- import {
25
- readVersionDocs,
26
- processDocMetadata,
27
- addDocNavigation,
28
- getMainDocId,
29
- } from './docs';
30
- import {getDocsDirPaths, readVersionsMetadata} from './versions';
31
-
25
+ import type {DocEnv} from './docs';
26
+ import {readVersionDocs, processDocMetadata, addDocNavigation} from './docs';
27
+ import {readVersionsMetadata} from './versions';
32
28
  import type {
33
- LoadedContent,
34
29
  SourceToPermalink,
35
- DocMetadataBase,
36
- VersionMetadata,
37
- LoadedVersion,
38
30
  DocFile,
39
31
  DocsMarkdownOption,
40
32
  VersionTag,
41
- DocFrontMatter,
33
+ FullVersion,
42
34
  } from './types';
43
35
  import type {RuleSetRule} from 'webpack';
44
36
  import {cliDocsVersionCommand} from './cli';
45
37
  import {VERSIONS_JSON_FILE} from './constants';
46
38
  import {toGlobalDataVersion} from './globalData';
47
39
  import {toTagDocListProp} from './props';
40
+ import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
48
41
  import {
49
42
  translateLoadedContent,
50
43
  getLoadedContentTranslationFiles,
@@ -55,19 +48,26 @@ import {createVersionRoutes} from './routes';
55
48
  import type {
56
49
  PropTagsListPage,
57
50
  PluginOptions,
51
+ DocMetadataBase,
52
+ VersionMetadata,
53
+ DocFrontMatter,
54
+ LoadedContent,
55
+ LoadedVersion,
58
56
  } from '@docusaurus/plugin-content-docs';
59
57
  import {createSidebarsUtils} from './sidebars/utils';
60
- import {getCategoryGeneratedIndexMetadataList} from './categoryGeneratedIndex';
58
+ import _ from 'lodash';
61
59
 
62
60
  export default async function pluginContentDocs(
63
61
  context: LoadContext,
64
62
  options: PluginOptions,
65
63
  ): Promise<Plugin<LoadedContent>> {
66
64
  const {siteDir, generatedFilesDir, baseUrl, siteConfig} = context;
65
+ // Mutate options to resolve sidebar path according to siteDir
66
+ options.sidebarPath = resolveSidebarPathOption(siteDir, options.sidebarPath);
67
67
 
68
68
  const versionsMetadata = await readVersionsMetadata({context, options});
69
69
 
70
- const pluginId = options.id ?? DEFAULT_PLUGIN_ID;
70
+ const pluginId = options.id;
71
71
 
72
72
  const pluginDataDirRoot = path.join(
73
73
  generatedFilesDir,
@@ -97,16 +97,11 @@ export default async function pluginContentDocs(
97
97
  .arguments('<version>')
98
98
  .description(commandDescription)
99
99
  .action((version) => {
100
- cliDocsVersionCommand(version, siteDir, pluginId, {
101
- path: options.path,
102
- sidebarPath: options.sidebarPath,
103
- sidebarCollapsed: options.sidebarCollapsed,
104
- sidebarCollapsible: options.sidebarCollapsible,
105
- });
100
+ cliDocsVersionCommand(version, options, context);
106
101
  });
107
102
  },
108
103
 
109
- async getTranslationFiles({content}) {
104
+ getTranslationFiles({content}) {
110
105
  return getLoadedContentTranslationFiles(content);
111
106
  },
112
107
 
@@ -114,7 +109,7 @@ export default async function pluginContentDocs(
114
109
  function getVersionPathsToWatch(version: VersionMetadata): string[] {
115
110
  const result = [
116
111
  ...options.include.flatMap((pattern) =>
117
- getDocsDirPaths(version).map(
112
+ getContentPathList(version).map(
118
113
  (docsDirPath) => `${docsDirPath}/${pattern}`,
119
114
  ),
120
115
  ),
@@ -150,6 +145,7 @@ export default async function pluginContentDocs(
150
145
  versionMetadata,
151
146
  context,
152
147
  options,
148
+ env: process.env.NODE_ENV as DocEnv,
153
149
  });
154
150
  }
155
151
  return Promise.all(docFiles.map(processVersionDoc));
@@ -158,14 +154,17 @@ export default async function pluginContentDocs(
158
154
  async function doLoadVersion(
159
155
  versionMetadata: VersionMetadata,
160
156
  ): Promise<LoadedVersion> {
161
- const docs: DocMetadataBase[] = await loadVersionDocsBase(
157
+ const docsBase: DocMetadataBase[] = await loadVersionDocsBase(
162
158
  versionMetadata,
163
159
  );
164
160
 
161
+ const [drafts, docs] = _.partition(docsBase, (doc) => doc.draft);
162
+
165
163
  const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, {
166
164
  sidebarItemsGenerator: options.sidebarItemsGenerator,
167
165
  numberPrefixParser: options.numberPrefixParser,
168
166
  docs,
167
+ drafts,
169
168
  version: versionMetadata,
170
169
  sidebarOptions: {
171
170
  sidebarCollapsed: options.sidebarCollapsed,
@@ -183,12 +182,8 @@ export default async function pluginContentDocs(
183
182
  sidebarsUtils,
184
183
  versionMetadata.sidebarFilePath as string,
185
184
  ),
185
+ drafts,
186
186
  sidebars,
187
- mainDocId: getMainDocId({docs, sidebarsUtils}),
188
- categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
189
- docs,
190
- sidebarsUtils,
191
- }),
192
187
  };
193
188
  }
194
189
 
@@ -219,8 +214,19 @@ export default async function pluginContentDocs(
219
214
  breadcrumbs,
220
215
  } = options;
221
216
  const {addRoute, createData, setGlobalData} = actions;
217
+ const versions: FullVersion[] = loadedVersions.map((version) => {
218
+ const sidebarsUtils = createSidebarsUtils(version.sidebars);
219
+ return {
220
+ ...version,
221
+ sidebarsUtils,
222
+ categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
223
+ docs: version.docs,
224
+ sidebarsUtils,
225
+ }),
226
+ };
227
+ });
222
228
 
223
- async function createVersionTagsRoutes(version: LoadedVersion) {
229
+ async function createVersionTagsRoutes(version: FullVersion) {
224
230
  const versionTags = getVersionTags(version.docs);
225
231
 
226
232
  // TODO tags should be a sub route of the version route
@@ -228,13 +234,13 @@ export default async function pluginContentDocs(
228
234
  const tagsProp: PropTagsListPage['tags'] = Object.values(
229
235
  versionTags,
230
236
  ).map((tagValue) => ({
231
- name: tagValue.name,
237
+ label: tagValue.label,
232
238
  permalink: tagValue.permalink,
233
239
  count: tagValue.docIds.length,
234
240
  }));
235
241
 
236
242
  // Only create /tags page if there are tags.
237
- if (Object.keys(tagsProp).length > 0) {
243
+ if (tagsProp.length > 0) {
238
244
  const tagsPropPath = await createData(
239
245
  `${docuHash(`tags-list-${version.versionName}-prop`)}.json`,
240
246
  JSON.stringify(tagsProp, null, 2),
@@ -276,9 +282,9 @@ export default async function pluginContentDocs(
276
282
  }
277
283
 
278
284
  await Promise.all(
279
- loadedVersions.map((loadedVersion) =>
285
+ versions.map((version) =>
280
286
  createVersionRoutes({
281
- loadedVersion,
287
+ version,
282
288
  docItemComponent,
283
289
  docLayoutComponent,
284
290
  docCategoryGeneratedIndexComponent,
@@ -290,11 +296,11 @@ export default async function pluginContentDocs(
290
296
  );
291
297
 
292
298
  // TODO tags should be a sub route of the version route
293
- await Promise.all(loadedVersions.map(createVersionTagsRoutes));
299
+ await Promise.all(versions.map(createVersionTagsRoutes));
294
300
 
295
301
  setGlobalData({
296
302
  path: normalizeUrl([baseUrl, options.routeBasePath]),
297
- versions: loadedVersions.map(toGlobalDataVersion),
303
+ versions: versions.map(toGlobalDataVersion),
298
304
  breadcrumbs,
299
305
  });
300
306
  },
@@ -331,7 +337,7 @@ export default async function pluginContentDocs(
331
337
  };
332
338
 
333
339
  function createMDXLoaderRule(): RuleSetRule {
334
- const contentDirs = versionsMetadata.flatMap(getDocsDirPaths);
340
+ const contentDirs = versionsMetadata.flatMap(getContentPathList);
335
341
  return {
336
342
  test: /\.mdx?$/i,
337
343
  include: contentDirs
@@ -6,12 +6,11 @@
6
6
  */
7
7
 
8
8
  import type {DocsMarkdownOption} from '../types';
9
- import {getDocsDirPaths} from '../versions';
10
- import {replaceMarkdownLinks} from '@docusaurus/utils';
9
+ import {replaceMarkdownLinks, getContentPathList} from '@docusaurus/utils';
11
10
 
12
11
  function getVersion(filePath: string, options: DocsMarkdownOption) {
13
12
  const versionFound = options.versionsMetadata.find((version) =>
14
- getDocsDirPaths(version).some((docsDirPath) =>
13
+ getContentPathList(version).some((docsDirPath) =>
15
14
  filePath.startsWith(docsDirPath),
16
15
  ),
17
16
  );