@docusaurus/plugin-content-docs 2.0.0-beta.12faed89d → 2.0.0-beta.13

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 (138) hide show
  1. package/lib/.tsbuildinfo +1 -1
  2. package/lib/categoryGeneratedIndex.d.ts +12 -0
  3. package/lib/categoryGeneratedIndex.js +37 -0
  4. package/lib/cli.d.ts +2 -2
  5. package/lib/cli.js +12 -34
  6. package/lib/client/docsClientUtils.d.ts +0 -3
  7. package/lib/client/docsClientUtils.js +19 -22
  8. package/lib/docFrontMatter.d.ts +1 -1
  9. package/lib/docFrontMatter.js +7 -3
  10. package/lib/docs.d.ts +25 -3
  11. package/lib/docs.js +125 -41
  12. package/lib/globalData.d.ts +1 -1
  13. package/lib/index.d.ts +1 -1
  14. package/lib/index.js +100 -131
  15. package/lib/lastUpdate.js +8 -9
  16. package/lib/markdown/index.d.ts +3 -6
  17. package/lib/markdown/index.js +3 -3
  18. package/lib/markdown/linkify.js +2 -2
  19. package/lib/numberPrefix.d.ts +1 -1
  20. package/lib/options.d.ts +3 -3
  21. package/lib/options.js +48 -11
  22. package/lib/props.d.ts +7 -2
  23. package/lib/props.js +60 -8
  24. package/lib/routes.d.ts +27 -0
  25. package/lib/routes.js +105 -0
  26. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +5 -2
  27. package/lib/sidebars/generator.js +216 -0
  28. package/lib/sidebars/index.d.ts +15 -0
  29. package/lib/sidebars/index.js +73 -0
  30. package/lib/sidebars/normalization.d.ts +14 -0
  31. package/lib/sidebars/normalization.js +77 -0
  32. package/lib/sidebars/processor.d.ts +18 -0
  33. package/lib/sidebars/processor.js +85 -0
  34. package/lib/sidebars/types.d.ts +127 -0
  35. package/lib/sidebars/types.js +8 -0
  36. package/lib/sidebars/utils.d.ts +35 -0
  37. package/lib/sidebars/utils.js +228 -0
  38. package/lib/sidebars/validation.d.ts +10 -0
  39. package/lib/sidebars/validation.js +138 -0
  40. package/lib/slug.d.ts +4 -3
  41. package/lib/slug.js +27 -15
  42. package/lib/tags.d.ts +8 -0
  43. package/lib/tags.js +20 -0
  44. package/lib/theme/hooks/useDocs.js +21 -21
  45. package/lib/translations.d.ts +2 -2
  46. package/lib/translations.js +71 -29
  47. package/lib/types.d.ts +52 -63
  48. package/lib/versions.d.ts +3 -3
  49. package/lib/versions.js +41 -22
  50. package/package.json +20 -20
  51. package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +3 -0
  52. package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +3 -0
  53. package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +3 -0
  54. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
  55. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +2 -0
  56. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +2 -0
  57. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +2 -0
  58. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +2 -0
  59. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +2 -0
  60. package/src/__tests__/__fixtures__/simple-site/sidebars.json +15 -1
  61. package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +1 -0
  62. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +6 -0
  63. package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +3 -0
  64. package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
  65. package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
  66. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +3 -0
  67. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +3 -0
  68. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +3 -0
  69. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +3 -0
  70. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +3 -0
  71. package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +2 -2
  72. package/src/__tests__/__snapshots__/cli.test.ts.snap +48 -73
  73. package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
  74. package/src/__tests__/__snapshots__/index.test.ts.snap +745 -97
  75. package/src/__tests__/__snapshots__/translations.test.ts.snap +45 -15
  76. package/src/__tests__/cli.test.ts +15 -11
  77. package/src/__tests__/docFrontMatter.test.ts +160 -45
  78. package/src/__tests__/docs.test.ts +311 -150
  79. package/src/__tests__/index.test.ts +108 -66
  80. package/src/__tests__/lastUpdate.test.ts +1 -1
  81. package/src/__tests__/options.test.ts +48 -3
  82. package/src/__tests__/props.test.ts +62 -0
  83. package/src/__tests__/slug.test.ts +127 -20
  84. package/src/__tests__/translations.test.ts +7 -1
  85. package/src/__tests__/versions.test.ts +73 -70
  86. package/src/categoryGeneratedIndex.ts +57 -0
  87. package/src/cli.ts +8 -41
  88. package/src/client/docsClientUtils.ts +14 -26
  89. package/{types.d.ts → src/deps.d.ts} +0 -0
  90. package/src/docFrontMatter.ts +9 -4
  91. package/src/docs.ts +158 -32
  92. package/src/globalData.ts +6 -1
  93. package/src/index.ts +125 -169
  94. package/src/lastUpdate.ts +10 -13
  95. package/src/markdown/index.ts +8 -12
  96. package/src/numberPrefix.ts +5 -3
  97. package/src/options.ts +59 -14
  98. package/src/plugin-content-docs.d.ts +173 -40
  99. package/src/props.ts +90 -15
  100. package/src/routes.ts +173 -0
  101. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
  102. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
  103. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
  104. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
  105. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
  106. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
  107. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
  108. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
  109. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
  110. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
  111. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
  112. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
  113. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
  114. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
  115. package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +36 -6
  116. package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +143 -18
  117. package/src/sidebars/__tests__/index.test.ts +204 -0
  118. package/src/sidebars/__tests__/processor.test.ts +237 -0
  119. package/src/sidebars/__tests__/utils.test.ts +695 -0
  120. package/src/sidebars/__tests__/validation.test.ts +105 -0
  121. package/src/sidebars/generator.ts +310 -0
  122. package/src/sidebars/index.ts +94 -0
  123. package/src/sidebars/normalization.ts +112 -0
  124. package/src/sidebars/processor.ts +154 -0
  125. package/src/sidebars/types.ts +211 -0
  126. package/src/sidebars/utils.ts +329 -0
  127. package/src/sidebars/validation.ts +168 -0
  128. package/src/slug.ts +32 -17
  129. package/src/tags.ts +19 -0
  130. package/src/translations.ts +103 -47
  131. package/src/types.ts +64 -107
  132. package/src/versions.ts +59 -25
  133. package/lib/sidebarItemsGenerator.js +0 -211
  134. package/lib/sidebars.d.ts +0 -43
  135. package/lib/sidebars.js +0 -320
  136. package/src/__tests__/sidebars.test.ts +0 -639
  137. package/src/sidebarItemsGenerator.ts +0 -307
  138. package/src/sidebars.ts +0 -522
@@ -13,9 +13,9 @@ import {
13
13
  readVersionsMetadata,
14
14
  } from '../versions';
15
15
  import {DEFAULT_OPTIONS} from '../options';
16
- import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
16
+ import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
17
17
  import {PluginOptions, VersionMetadata} from '../types';
18
- import {I18n} from '@docusaurus/types';
18
+ import type {I18n} from '@docusaurus/types';
19
19
 
20
20
  const DefaultI18N: I18n = {
21
21
  currentLocale: 'en',
@@ -77,10 +77,13 @@ describe('simple site', () => {
77
77
  isLast: true,
78
78
  routePriority: -1,
79
79
  sidebarFilePath: undefined,
80
+ tagsPath: '/docs/tags',
80
81
  versionLabel: 'Next',
81
82
  versionName: 'current',
82
83
  versionPath: '/docs',
83
- versionBanner: 'none',
84
+ versionBanner: null,
85
+ versionBadge: false,
86
+ versionClassName: 'docs-version-current',
84
87
  };
85
88
  return {simpleSiteDir, defaultOptions, defaultContext, vCurrent};
86
89
  }
@@ -111,6 +114,7 @@ describe('simple site', () => {
111
114
  {
112
115
  ...vCurrent,
113
116
  versionPath: '/myBaseUrl/docs',
117
+ tagsPath: '/myBaseUrl/docs/tags',
114
118
  },
115
119
  ]);
116
120
  });
@@ -141,6 +145,7 @@ describe('simple site', () => {
141
145
  versionLabel: 'current-label',
142
146
  routePriority: undefined,
143
147
  sidebarFilePath: undefined,
148
+ tagsPath: '/myBaseUrl/docs/current-path/tags',
144
149
  versionEditUrl: undefined,
145
150
  versionEditUrlLocalized: undefined,
146
151
  },
@@ -232,10 +237,13 @@ describe('versioned site, pluginId=default', () => {
232
237
  isLast: false,
233
238
  routePriority: undefined,
234
239
  sidebarFilePath: path.join(versionedSiteDir, 'sidebars.json'),
240
+ tagsPath: '/docs/next/tags',
235
241
  versionLabel: 'Next',
236
242
  versionName: 'current',
237
243
  versionPath: '/docs/next',
238
244
  versionBanner: 'unreleased',
245
+ versionBadge: true,
246
+ versionClassName: 'docs-version-current',
239
247
  };
240
248
 
241
249
  const v101: VersionMetadata = {
@@ -250,10 +258,13 @@ describe('versioned site, pluginId=default', () => {
250
258
  versionedSiteDir,
251
259
  'versioned_sidebars/version-1.0.1-sidebars.json',
252
260
  ),
261
+ tagsPath: '/docs/tags',
253
262
  versionLabel: '1.0.1',
254
263
  versionName: '1.0.1',
255
264
  versionPath: '/docs',
256
- versionBanner: 'none',
265
+ versionBanner: null,
266
+ versionBadge: true,
267
+ versionClassName: 'docs-version-1.0.1',
257
268
  };
258
269
 
259
270
  const v100: VersionMetadata = {
@@ -268,10 +279,13 @@ describe('versioned site, pluginId=default', () => {
268
279
  versionedSiteDir,
269
280
  'versioned_sidebars/version-1.0.0-sidebars.json',
270
281
  ),
282
+ tagsPath: '/docs/1.0.0/tags',
271
283
  versionLabel: '1.0.0',
272
284
  versionName: '1.0.0',
273
285
  versionPath: '/docs/1.0.0',
274
286
  versionBanner: 'unmaintained',
287
+ versionBadge: true,
288
+ versionClassName: 'docs-version-1.0.0',
275
289
  };
276
290
 
277
291
  const vwithSlugs: VersionMetadata = {
@@ -289,10 +303,13 @@ describe('versioned site, pluginId=default', () => {
289
303
  versionedSiteDir,
290
304
  'versioned_sidebars/version-withSlugs-sidebars.json',
291
305
  ),
306
+ tagsPath: '/docs/withSlugs/tags',
292
307
  versionLabel: 'withSlugs',
293
308
  versionName: 'withSlugs',
294
309
  versionPath: '/docs/withSlugs',
295
310
  versionBanner: 'unmaintained',
311
+ versionBadge: true,
312
+ versionClassName: 'docs-version-withSlugs',
296
313
  };
297
314
 
298
315
  return {
@@ -307,14 +324,8 @@ describe('versioned site, pluginId=default', () => {
307
324
  }
308
325
 
309
326
  test('readVersionsMetadata versioned site', async () => {
310
- const {
311
- defaultOptions,
312
- defaultContext,
313
- vCurrent,
314
- v101,
315
- v100,
316
- vwithSlugs,
317
- } = await loadSite();
327
+ const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
328
+ await loadSite();
318
329
 
319
330
  const versionsMetadata = readVersionsMetadata({
320
331
  options: defaultOptions,
@@ -325,13 +336,8 @@ describe('versioned site, pluginId=default', () => {
325
336
  });
326
337
 
327
338
  test('readVersionsMetadata versioned site with includeCurrentVersion=false', async () => {
328
- const {
329
- defaultOptions,
330
- defaultContext,
331
- v101,
332
- v100,
333
- vwithSlugs,
334
- } = await loadSite();
339
+ const {defaultOptions, defaultContext, v101, v100, vwithSlugs} =
340
+ await loadSite();
335
341
 
336
342
  const versionsMetadata = readVersionsMetadata({
337
343
  options: {...defaultOptions, includeCurrentVersion: false},
@@ -347,14 +353,8 @@ describe('versioned site, pluginId=default', () => {
347
353
  });
348
354
 
349
355
  test('readVersionsMetadata versioned site with version options', async () => {
350
- const {
351
- defaultOptions,
352
- defaultContext,
353
- vCurrent,
354
- v101,
355
- v100,
356
- vwithSlugs,
357
- } = await loadSite();
356
+ const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
357
+ await loadSite();
358
358
 
359
359
  const versionsMetadata = readVersionsMetadata({
360
360
  options: {
@@ -364,6 +364,8 @@ describe('versioned site, pluginId=default', () => {
364
364
  current: {
365
365
  path: 'current-path',
366
366
  banner: 'unmaintained',
367
+ badge: false,
368
+ className: 'custom-current-className',
367
369
  },
368
370
  '1.0.0': {
369
371
  label: '1.0.0-label',
@@ -377,13 +379,17 @@ describe('versioned site, pluginId=default', () => {
377
379
  expect(versionsMetadata).toEqual([
378
380
  {
379
381
  ...vCurrent,
382
+ tagsPath: '/docs/current-path/tags',
380
383
  versionPath: '/docs/current-path',
381
384
  versionBanner: 'unmaintained',
385
+ versionBadge: false,
386
+ versionClassName: 'custom-current-className',
382
387
  },
383
388
  {
384
389
  ...v101,
385
390
  isLast: false,
386
391
  routePriority: undefined,
392
+ tagsPath: '/docs/1.0.1/tags',
387
393
  versionPath: '/docs/1.0.1',
388
394
  versionBanner: 'unreleased',
389
395
  },
@@ -391,6 +397,7 @@ describe('versioned site, pluginId=default', () => {
391
397
  ...v100,
392
398
  isLast: true,
393
399
  routePriority: -1,
400
+ tagsPath: '/docs/tags',
394
401
  versionLabel: '1.0.0-label',
395
402
  versionPath: '/docs',
396
403
  versionBanner: 'unreleased',
@@ -400,19 +407,13 @@ describe('versioned site, pluginId=default', () => {
400
407
  });
401
408
 
402
409
  test('readVersionsMetadata versioned site with editUrl', async () => {
403
- const {
404
- defaultOptions,
405
- defaultContext,
406
- vCurrent,
407
- v101,
408
- v100,
409
- vwithSlugs,
410
- } = await loadSite();
410
+ const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
411
+ await loadSite();
411
412
 
412
413
  const versionsMetadata = readVersionsMetadata({
413
414
  options: {
414
415
  ...defaultOptions,
415
- editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/',
416
+ editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/',
416
417
  },
417
418
  context: defaultContext,
418
419
  });
@@ -421,48 +422,42 @@ describe('versioned site, pluginId=default', () => {
421
422
  {
422
423
  ...vCurrent,
423
424
  versionEditUrl:
424
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
425
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
425
426
  versionEditUrlLocalized:
426
- 'https://github.com/facebook/docusaurus/edit/master/website/i18n/en/docusaurus-plugin-content-docs/current',
427
+ 'https://github.com/facebook/docusaurus/edit/main/website/i18n/en/docusaurus-plugin-content-docs/current',
427
428
  },
428
429
  {
429
430
  ...v101,
430
431
  versionEditUrl:
431
- 'https://github.com/facebook/docusaurus/edit/master/website/versioned_docs/version-1.0.1',
432
+ 'https://github.com/facebook/docusaurus/edit/main/website/versioned_docs/version-1.0.1',
432
433
  versionEditUrlLocalized:
433
- 'https://github.com/facebook/docusaurus/edit/master/website/i18n/en/docusaurus-plugin-content-docs/version-1.0.1',
434
+ 'https://github.com/facebook/docusaurus/edit/main/website/i18n/en/docusaurus-plugin-content-docs/version-1.0.1',
434
435
  },
435
436
  {
436
437
  ...v100,
437
438
  versionEditUrl:
438
- 'https://github.com/facebook/docusaurus/edit/master/website/versioned_docs/version-1.0.0',
439
+ 'https://github.com/facebook/docusaurus/edit/main/website/versioned_docs/version-1.0.0',
439
440
  versionEditUrlLocalized:
440
- 'https://github.com/facebook/docusaurus/edit/master/website/i18n/en/docusaurus-plugin-content-docs/version-1.0.0',
441
+ 'https://github.com/facebook/docusaurus/edit/main/website/i18n/en/docusaurus-plugin-content-docs/version-1.0.0',
441
442
  },
442
443
  {
443
444
  ...vwithSlugs,
444
445
  versionEditUrl:
445
- 'https://github.com/facebook/docusaurus/edit/master/website/versioned_docs/version-withSlugs',
446
+ 'https://github.com/facebook/docusaurus/edit/main/website/versioned_docs/version-withSlugs',
446
447
  versionEditUrlLocalized:
447
- 'https://github.com/facebook/docusaurus/edit/master/website/i18n/en/docusaurus-plugin-content-docs/version-withSlugs',
448
+ 'https://github.com/facebook/docusaurus/edit/main/website/i18n/en/docusaurus-plugin-content-docs/version-withSlugs',
448
449
  },
449
450
  ]);
450
451
  });
451
452
 
452
453
  test('readVersionsMetadata versioned site with editUrl and editCurrentVersion=true', async () => {
453
- const {
454
- defaultOptions,
455
- defaultContext,
456
- vCurrent,
457
- v101,
458
- v100,
459
- vwithSlugs,
460
- } = await loadSite();
454
+ const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
455
+ await loadSite();
461
456
 
462
457
  const versionsMetadata = readVersionsMetadata({
463
458
  options: {
464
459
  ...defaultOptions,
465
- editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/',
460
+ editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/',
466
461
  editCurrentVersion: true,
467
462
  },
468
463
  context: defaultContext,
@@ -472,30 +467,30 @@ describe('versioned site, pluginId=default', () => {
472
467
  {
473
468
  ...vCurrent,
474
469
  versionEditUrl:
475
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
470
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
476
471
  versionEditUrlLocalized:
477
- 'https://github.com/facebook/docusaurus/edit/master/website/i18n/en/docusaurus-plugin-content-docs/current',
472
+ 'https://github.com/facebook/docusaurus/edit/main/website/i18n/en/docusaurus-plugin-content-docs/current',
478
473
  },
479
474
  {
480
475
  ...v101,
481
476
  versionEditUrl:
482
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
477
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
483
478
  versionEditUrlLocalized:
484
- 'https://github.com/facebook/docusaurus/edit/master/website/i18n/en/docusaurus-plugin-content-docs/current',
479
+ 'https://github.com/facebook/docusaurus/edit/main/website/i18n/en/docusaurus-plugin-content-docs/current',
485
480
  },
486
481
  {
487
482
  ...v100,
488
483
  versionEditUrl:
489
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
484
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
490
485
  versionEditUrlLocalized:
491
- 'https://github.com/facebook/docusaurus/edit/master/website/i18n/en/docusaurus-plugin-content-docs/current',
486
+ 'https://github.com/facebook/docusaurus/edit/main/website/i18n/en/docusaurus-plugin-content-docs/current',
492
487
  },
493
488
  {
494
489
  ...vwithSlugs,
495
490
  versionEditUrl:
496
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
491
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
497
492
  versionEditUrlLocalized:
498
- 'https://github.com/facebook/docusaurus/edit/master/website/i18n/en/docusaurus-plugin-content-docs/current',
493
+ 'https://github.com/facebook/docusaurus/edit/main/website/i18n/en/docusaurus-plugin-content-docs/current',
499
494
  },
500
495
  ]);
501
496
  });
@@ -528,8 +523,10 @@ describe('versioned site, pluginId=default', () => {
528
523
  ...vCurrent,
529
524
  isLast: true,
530
525
  routePriority: -1,
526
+ tagsPath: '/docs/tags',
531
527
  versionPath: '/docs',
532
- versionBanner: 'none',
528
+ versionBanner: null,
529
+ versionBadge: false,
533
530
  },
534
531
  ]);
535
532
  });
@@ -603,11 +600,9 @@ describe('versioned site, pluginId=default', () => {
603
600
  test('readVersionsMetadata versioned site with invalid versions.json file', async () => {
604
601
  const {defaultOptions, defaultContext} = await loadSite();
605
602
 
606
- const mock = jest.spyOn(JSON, 'parse').mockImplementationOnce(() => {
607
- return {
608
- invalid: 'json',
609
- };
610
- });
603
+ const mock = jest.spyOn(JSON, 'parse').mockImplementationOnce(() => ({
604
+ invalid: 'json',
605
+ }));
611
606
 
612
607
  expect(() => {
613
608
  readVersionsMetadata({
@@ -648,10 +643,13 @@ describe('versioned site, pluginId=community', () => {
648
643
  isLast: false,
649
644
  routePriority: undefined,
650
645
  sidebarFilePath: path.join(versionedSiteDir, 'sidebars.json'),
646
+ tagsPath: '/communityBasePath/next/tags',
651
647
  versionLabel: 'Next',
652
648
  versionName: 'current',
653
649
  versionPath: '/communityBasePath/next',
654
650
  versionBanner: 'unreleased',
651
+ versionBadge: true,
652
+ versionClassName: 'docs-version-current',
655
653
  };
656
654
 
657
655
  const v100: VersionMetadata = {
@@ -669,10 +667,13 @@ describe('versioned site, pluginId=community', () => {
669
667
  versionedSiteDir,
670
668
  'community_versioned_sidebars/version-1.0.0-sidebars.json',
671
669
  ),
670
+ tagsPath: '/communityBasePath/tags',
672
671
  versionLabel: '1.0.0',
673
672
  versionName: '1.0.0',
674
673
  versionPath: '/communityBasePath',
675
- versionBanner: 'none',
674
+ versionBanner: null,
675
+ versionBadge: true,
676
+ versionClassName: 'docs-version-1.0.0',
676
677
  };
677
678
 
678
679
  return {versionedSiteDir, defaultOptions, defaultContext, vCurrent, v100};
@@ -699,7 +700,7 @@ describe('versioned site, pluginId=community', () => {
699
700
 
700
701
  expect(versionsMetadata).toEqual([
701
702
  // vCurrent removed
702
- v100,
703
+ {...v100, versionBadge: false},
703
704
  ]);
704
705
  });
705
706
 
@@ -716,8 +717,10 @@ describe('versioned site, pluginId=community', () => {
716
717
  ...vCurrent,
717
718
  isLast: true,
718
719
  routePriority: -1,
720
+ tagsPath: '/communityBasePath/tags',
719
721
  versionPath: '/communityBasePath',
720
- versionBanner: 'none',
722
+ versionBanner: null,
723
+ versionBadge: false,
721
724
  },
722
725
  ]);
723
726
  });
@@ -0,0 +1,57 @@
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 {CategoryGeneratedIndexMetadata, DocMetadataBase} from './types';
9
+ import {SidebarItemCategoryWithGeneratedIndex} from './sidebars/types';
10
+ import {SidebarsUtils, toNavigationLink} from './sidebars/utils';
11
+ import {createDocsByIdIndex} from './docs';
12
+
13
+ function getCategoryGeneratedIndexMetadata({
14
+ category,
15
+ sidebarsUtils,
16
+ docsById,
17
+ }: {
18
+ category: SidebarItemCategoryWithGeneratedIndex;
19
+ sidebarsUtils: SidebarsUtils;
20
+ docsById: Record<string, DocMetadataBase>;
21
+ }): CategoryGeneratedIndexMetadata {
22
+ const {sidebarName, previous, next} =
23
+ sidebarsUtils.getCategoryGeneratedIndexNavigation(category.link.permalink);
24
+ if (!sidebarName) {
25
+ throw new Error('unexpected');
26
+ }
27
+
28
+ return {
29
+ title: category.link.title ?? category.label,
30
+ description: category.link.description,
31
+ slug: category.link.slug,
32
+ permalink: category.link.permalink,
33
+ sidebar: sidebarName,
34
+ previous: toNavigationLink(previous, docsById),
35
+ next: toNavigationLink(next, docsById),
36
+ };
37
+ }
38
+
39
+ export function getCategoryGeneratedIndexMetadataList({
40
+ docs,
41
+ sidebarsUtils,
42
+ }: {
43
+ sidebarsUtils: SidebarsUtils;
44
+ docs: DocMetadataBase[];
45
+ }): CategoryGeneratedIndexMetadata[] {
46
+ const docsById = createDocsByIdIndex(docs);
47
+
48
+ const categoryGeneratedIndexItems =
49
+ sidebarsUtils.getCategoryGeneratedIndexList();
50
+ return categoryGeneratedIndexItems.map((category) =>
51
+ getCategoryGeneratedIndexMetadata({
52
+ category,
53
+ sidebarsUtils,
54
+ docsById,
55
+ }),
56
+ );
57
+ }
package/src/cli.ts CHANGED
@@ -12,13 +12,9 @@ import {
12
12
  } from './versions';
13
13
  import fs from 'fs-extra';
14
14
  import path from 'path';
15
- import {
16
- PathOptions,
17
- UnprocessedSidebarItem,
18
- UnprocessedSidebars,
19
- } from './types';
20
- import {loadSidebars, resolveSidebarPathOption} from './sidebars';
21
- import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
15
+ import type {PathOptions, SidebarOptions} from './types';
16
+ import {loadSidebarsFile, resolveSidebarPathOption} from './sidebars';
17
+ import {DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
22
18
 
23
19
  function createVersionedSidebarFile({
24
20
  siteDir,
@@ -32,41 +28,13 @@ function createVersionedSidebarFile({
32
28
  version: string;
33
29
  }) {
34
30
  // Load current sidebar and create a new versioned sidebars file (if needed).
35
- const loadedSidebars = loadSidebars(sidebarPath);
31
+ // Note: we don't need the sidebars file to be normalized: it's ok to let plugin option changes to impact older, versioned sidebars
32
+ const sidebars = loadSidebarsFile(sidebarPath);
36
33
 
37
34
  // Do not create a useless versioned sidebars file if sidebars file is empty or sidebars are disabled/false)
38
- const shouldCreateVersionedSidebarFile =
39
- Object.keys(loadedSidebars).length > 0;
35
+ const shouldCreateVersionedSidebarFile = Object.keys(sidebars).length > 0;
40
36
 
41
37
  if (shouldCreateVersionedSidebarFile) {
42
- // TODO @slorber: this "version prefix" in versioned sidebars looks like a bad idea to me
43
- // TODO try to get rid of it
44
- // Transform id in original sidebar to versioned id.
45
- const normalizeItem = (
46
- item: UnprocessedSidebarItem,
47
- ): UnprocessedSidebarItem => {
48
- switch (item.type) {
49
- case 'category':
50
- return {...item, items: item.items.map(normalizeItem)};
51
- case 'ref':
52
- case 'doc':
53
- return {
54
- type: item.type,
55
- id: `version-${version}/${item.id}`,
56
- };
57
- default:
58
- return item;
59
- }
60
- };
61
-
62
- const versionedSidebar: UnprocessedSidebars = Object.entries(
63
- loadedSidebars,
64
- ).reduce((acc: UnprocessedSidebars, [sidebarId, sidebarItems]) => {
65
- const newVersionedSidebarId = `version-${version}/${sidebarId}`;
66
- acc[newVersionedSidebarId] = sidebarItems.map(normalizeItem);
67
- return acc;
68
- }, {});
69
-
70
38
  const versionedSidebarsDir = getVersionedSidebarsDirPath(siteDir, pluginId);
71
39
  const newSidebarFile = path.join(
72
40
  versionedSidebarsDir,
@@ -75,19 +43,18 @@ function createVersionedSidebarFile({
75
43
  fs.ensureDirSync(path.dirname(newSidebarFile));
76
44
  fs.writeFileSync(
77
45
  newSidebarFile,
78
- `${JSON.stringify(versionedSidebar, null, 2)}\n`,
46
+ `${JSON.stringify(sidebars, null, 2)}\n`,
79
47
  'utf8',
80
48
  );
81
49
  }
82
50
  }
83
51
 
84
52
  // Tests depend on non-default export for mocking.
85
- // eslint-disable-next-line import/prefer-default-export
86
53
  export function cliDocsVersionCommand(
87
54
  version: string | null | undefined,
88
55
  siteDir: string,
89
56
  pluginId: string,
90
- options: PathOptions,
57
+ options: PathOptions & SidebarOptions,
91
58
  ): void {
92
59
  // It wouldn't be very user-friendly to show a [default] log prefix,
93
60
  // so we use [docs] instead of [default]
@@ -20,35 +20,23 @@ export type ActivePlugin = {
20
20
  pluginData: GlobalPluginData;
21
21
  };
22
22
 
23
- export type GetActivePluginOptions = {failfast?: boolean};
23
+ export type GetActivePluginOptions = {failfast?: boolean}; // use fail-fast option if you know for sure one plugin instance is active
24
24
 
25
25
  // get the data of the plugin that is currently "active"
26
26
  // ie the docs of that plugin are currently browsed
27
27
  // it is useful to support multiple docs plugin instances
28
- export function getActivePlugin(
29
- allPluginDatas: Record<string, GlobalPluginData>,
30
- pathname: string,
31
- options: {failfast: true}, // use fail-fast option if you know for sure one plugin instance is active
32
- ): ActivePlugin;
33
- export function getActivePlugin(
34
- allPluginDatas: Record<string, GlobalPluginData>,
35
- pathname: string,
36
- options?: GetActivePluginOptions,
37
- ): ActivePlugin | undefined;
38
-
39
28
  export function getActivePlugin(
40
29
  allPluginDatas: Record<string, GlobalPluginData>,
41
30
  pathname: string,
42
31
  options: GetActivePluginOptions = {},
43
32
  ): ActivePlugin | undefined {
44
33
  const activeEntry = Object.entries(allPluginDatas).find(
45
- ([_id, pluginData]) => {
46
- return !!matchPath(pathname, {
34
+ ([_id, pluginData]) =>
35
+ !!matchPath(pathname, {
47
36
  path: pluginData.path,
48
37
  exact: false,
49
38
  strict: false,
50
- });
51
- },
39
+ }),
52
40
  );
53
41
 
54
42
  const activePlugin: ActivePlugin | undefined = activeEntry
@@ -74,9 +62,8 @@ export type ActiveDocContext = {
74
62
  alternateDocVersions: Record<string, Doc>;
75
63
  };
76
64
 
77
- export const getLatestVersion = (data: GlobalPluginData): Version => {
78
- return data.versions.find((version) => version.isLast)!;
79
- };
65
+ export const getLatestVersion = (data: GlobalPluginData): Version =>
66
+ data.versions.find((version) => version.isLast)!;
80
67
 
81
68
  // Note: return undefined on doc-unrelated pages,
82
69
  // because there's no version currently considered as active
@@ -91,13 +78,14 @@ export const getActiveVersion = (
91
78
  ...data.versions.filter((version) => version !== lastVersion),
92
79
  lastVersion,
93
80
  ];
94
- return orderedVersionsMetadata.find((version) => {
95
- return !!matchPath(pathname, {
96
- path: version.path,
97
- exact: false,
98
- strict: false,
99
- });
100
- });
81
+ return orderedVersionsMetadata.find(
82
+ (version) =>
83
+ !!matchPath(pathname, {
84
+ path: version.path,
85
+ exact: false,
86
+ strict: false,
87
+ }),
88
+ );
101
89
  };
102
90
 
103
91
  export const getActiveDocContext = (
File without changes
@@ -5,17 +5,17 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- /* eslint-disable camelcase */
9
-
10
8
  import {
11
9
  JoiFrontMatter as Joi, // Custom instance for frontmatter
12
10
  URISchema,
11
+ FrontMatterTagsSchema,
12
+ FrontMatterTOCHeadingLevels,
13
13
  validateFrontMatter,
14
14
  } from '@docusaurus/utils-validation';
15
- import {DocFrontMatter} from './types';
15
+ import type {DocFrontMatter} from './types';
16
16
 
17
17
  // NOTE: we don't add any default value on purpose here
18
- // We don't want default values to magically appear in doc metadatas and props
18
+ // We don't want default values to magically appear in doc metadata and props
19
19
  // While the user did not provide those values explicitly
20
20
  // We use default values in code instead
21
21
  const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
@@ -29,9 +29,14 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
29
29
  slug: Joi.string(),
30
30
  sidebar_label: Joi.string(),
31
31
  sidebar_position: Joi.number(),
32
+ sidebar_class_name: Joi.string(),
33
+ tags: FrontMatterTagsSchema,
32
34
  pagination_label: Joi.string(),
33
35
  custom_edit_url: URISchema.allow('', null),
34
36
  parse_number_prefixes: Joi.boolean(),
37
+ pagination_next: Joi.string().allow(null),
38
+ pagination_prev: Joi.string().allow(null),
39
+ ...FrontMatterTOCHeadingLevels,
35
40
  }).unknown();
36
41
 
37
42
  export function validateDocFrontMatter(