@docusaurus/plugin-content-docs 2.0.0-beta.8bda3b2db → 2.0.0-beta.9

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 (117) hide show
  1. package/lib/.tsbuildinfo +1 -1
  2. package/lib/cli.d.ts +2 -2
  3. package/lib/cli.js +20 -24
  4. package/lib/client/docsClientUtils.d.ts +1 -4
  5. package/lib/client/docsClientUtils.js +12 -16
  6. package/lib/docFrontMatter.js +7 -3
  7. package/lib/docs.d.ts +4 -2
  8. package/lib/docs.js +77 -23
  9. package/lib/index.js +88 -94
  10. package/lib/lastUpdate.js +8 -8
  11. package/lib/markdown/index.d.ts +3 -6
  12. package/lib/markdown/index.js +3 -3
  13. package/lib/markdown/linkify.js +2 -2
  14. package/lib/options.d.ts +1 -1
  15. package/lib/options.js +39 -11
  16. package/lib/props.d.ts +7 -2
  17. package/lib/props.js +27 -4
  18. package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +3 -1
  19. package/lib/sidebars/generator.js +174 -0
  20. package/lib/sidebars/index.d.ts +14 -0
  21. package/lib/sidebars/index.js +64 -0
  22. package/lib/sidebars/normalization.d.ts +9 -0
  23. package/lib/sidebars/normalization.js +58 -0
  24. package/lib/sidebars/processor.d.ts +16 -0
  25. package/lib/sidebars/processor.js +70 -0
  26. package/lib/sidebars/types.d.ts +87 -0
  27. package/lib/sidebars/types.js +13 -0
  28. package/lib/sidebars/utils.d.ts +22 -0
  29. package/lib/sidebars/utils.js +101 -0
  30. package/lib/sidebars/validation.d.ts +8 -0
  31. package/lib/sidebars/validation.js +102 -0
  32. package/lib/slug.js +4 -4
  33. package/lib/tags.d.ts +8 -0
  34. package/lib/tags.js +22 -0
  35. package/lib/theme/hooks/useDocs.js +24 -21
  36. package/lib/translations.d.ts +1 -1
  37. package/lib/translations.js +13 -13
  38. package/lib/types.d.ts +35 -58
  39. package/lib/versions.d.ts +1 -1
  40. package/lib/versions.js +75 -22
  41. package/package.json +15 -14
  42. package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +3 -0
  43. package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +3 -0
  44. package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +3 -0
  45. package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
  46. package/src/__tests__/__fixtures__/simple-site/docs/hello.md +1 -0
  47. package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +2 -0
  48. package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +2 -0
  49. package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +2 -0
  50. package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +2 -0
  51. package/src/__tests__/__fixtures__/simple-site/sidebars.json +15 -1
  52. package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +6 -0
  53. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +3 -0
  54. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +3 -0
  55. package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +3 -0
  56. package/src/__tests__/__snapshots__/cli.test.ts.snap +33 -0
  57. package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
  58. package/src/__tests__/__snapshots__/index.test.ts.snap +478 -60
  59. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -3
  60. package/src/__tests__/cli.test.ts +14 -10
  61. package/src/__tests__/docFrontMatter.test.ts +163 -48
  62. package/src/__tests__/docs.test.ts +167 -21
  63. package/src/__tests__/index.test.ts +74 -30
  64. package/src/__tests__/lastUpdate.test.ts +3 -2
  65. package/src/__tests__/options.test.ts +46 -3
  66. package/src/__tests__/props.test.ts +62 -0
  67. package/src/__tests__/translations.test.ts +0 -1
  68. package/src/__tests__/versions.test.ts +88 -60
  69. package/src/cli.ts +27 -30
  70. package/src/client/__tests__/docsClientUtils.test.ts +4 -5
  71. package/src/client/docsClientUtils.ts +6 -27
  72. package/src/docFrontMatter.ts +8 -3
  73. package/src/docs.ts +92 -9
  74. package/src/index.ts +114 -121
  75. package/src/lastUpdate.ts +10 -6
  76. package/src/markdown/index.ts +8 -12
  77. package/src/numberPrefix.ts +4 -2
  78. package/src/options.ts +47 -17
  79. package/src/plugin-content-docs.d.ts +121 -34
  80. package/src/props.ts +42 -6
  81. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
  82. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
  83. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
  84. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
  85. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
  86. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
  87. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
  88. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
  89. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
  90. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
  91. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
  92. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
  93. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
  94. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
  95. package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +21 -6
  96. package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +29 -7
  97. package/src/sidebars/__tests__/index.test.ts +202 -0
  98. package/src/sidebars/__tests__/processor.test.ts +148 -0
  99. package/src/sidebars/__tests__/utils.test.ts +395 -0
  100. package/src/sidebars/generator.ts +253 -0
  101. package/src/sidebars/index.ts +84 -0
  102. package/src/sidebars/normalization.ts +88 -0
  103. package/src/sidebars/processor.ts +124 -0
  104. package/src/sidebars/types.ts +156 -0
  105. package/src/sidebars/utils.ts +146 -0
  106. package/src/sidebars/validation.ts +124 -0
  107. package/src/tags.ts +21 -0
  108. package/src/theme/hooks/useDocs.ts +5 -1
  109. package/src/translations.ts +26 -36
  110. package/src/types.ts +48 -99
  111. package/src/versions.ts +109 -17
  112. package/lib/sidebarItemsGenerator.js +0 -211
  113. package/lib/sidebars.d.ts +0 -43
  114. package/lib/sidebars.js +0 -319
  115. package/src/__tests__/sidebars.test.ts +0 -639
  116. package/src/sidebarItemsGenerator.ts +0 -307
  117. package/src/sidebars.ts +0 -506
@@ -21,6 +21,7 @@ const DefaultI18N: I18n = {
21
21
  currentLocale: 'en',
22
22
  locales: ['en'],
23
23
  defaultLocale: 'en',
24
+ localeConfigs: {},
24
25
  };
25
26
 
26
27
  describe('version paths', () => {
@@ -76,9 +77,13 @@ describe('simple site', () => {
76
77
  isLast: true,
77
78
  routePriority: -1,
78
79
  sidebarFilePath: undefined,
80
+ tagsPath: '/docs/tags',
79
81
  versionLabel: 'Next',
80
82
  versionName: 'current',
81
83
  versionPath: '/docs',
84
+ versionBanner: null,
85
+ versionBadge: false,
86
+ versionClassName: 'docs-version-current',
82
87
  };
83
88
  return {simpleSiteDir, defaultOptions, defaultContext, vCurrent};
84
89
  }
@@ -109,6 +114,7 @@ describe('simple site', () => {
109
114
  {
110
115
  ...vCurrent,
111
116
  versionPath: '/myBaseUrl/docs',
117
+ tagsPath: '/myBaseUrl/docs/tags',
112
118
  },
113
119
  ]);
114
120
  });
@@ -139,6 +145,7 @@ describe('simple site', () => {
139
145
  versionLabel: 'current-label',
140
146
  routePriority: undefined,
141
147
  sidebarFilePath: undefined,
148
+ tagsPath: '/myBaseUrl/docs/current-path/tags',
142
149
  versionEditUrl: undefined,
143
150
  versionEditUrlLocalized: undefined,
144
151
  },
@@ -230,9 +237,13 @@ describe('versioned site, pluginId=default', () => {
230
237
  isLast: false,
231
238
  routePriority: undefined,
232
239
  sidebarFilePath: path.join(versionedSiteDir, 'sidebars.json'),
240
+ tagsPath: '/docs/next/tags',
233
241
  versionLabel: 'Next',
234
242
  versionName: 'current',
235
243
  versionPath: '/docs/next',
244
+ versionBanner: 'unreleased',
245
+ versionBadge: true,
246
+ versionClassName: 'docs-version-current',
236
247
  };
237
248
 
238
249
  const v101: VersionMetadata = {
@@ -247,9 +258,13 @@ describe('versioned site, pluginId=default', () => {
247
258
  versionedSiteDir,
248
259
  'versioned_sidebars/version-1.0.1-sidebars.json',
249
260
  ),
261
+ tagsPath: '/docs/tags',
250
262
  versionLabel: '1.0.1',
251
263
  versionName: '1.0.1',
252
264
  versionPath: '/docs',
265
+ versionBanner: null,
266
+ versionBadge: true,
267
+ versionClassName: 'docs-version-1.0.1',
253
268
  };
254
269
 
255
270
  const v100: VersionMetadata = {
@@ -264,9 +279,13 @@ describe('versioned site, pluginId=default', () => {
264
279
  versionedSiteDir,
265
280
  'versioned_sidebars/version-1.0.0-sidebars.json',
266
281
  ),
282
+ tagsPath: '/docs/1.0.0/tags',
267
283
  versionLabel: '1.0.0',
268
284
  versionName: '1.0.0',
269
285
  versionPath: '/docs/1.0.0',
286
+ versionBanner: 'unmaintained',
287
+ versionBadge: true,
288
+ versionClassName: 'docs-version-1.0.0',
270
289
  };
271
290
 
272
291
  const vwithSlugs: VersionMetadata = {
@@ -284,9 +303,13 @@ describe('versioned site, pluginId=default', () => {
284
303
  versionedSiteDir,
285
304
  'versioned_sidebars/version-withSlugs-sidebars.json',
286
305
  ),
306
+ tagsPath: '/docs/withSlugs/tags',
287
307
  versionLabel: 'withSlugs',
288
308
  versionName: 'withSlugs',
289
309
  versionPath: '/docs/withSlugs',
310
+ versionBanner: 'unmaintained',
311
+ versionBadge: true,
312
+ versionClassName: 'docs-version-withSlugs',
290
313
  };
291
314
 
292
315
  return {
@@ -301,14 +324,8 @@ describe('versioned site, pluginId=default', () => {
301
324
  }
302
325
 
303
326
  test('readVersionsMetadata versioned site', async () => {
304
- const {
305
- defaultOptions,
306
- defaultContext,
307
- vCurrent,
308
- v101,
309
- v100,
310
- vwithSlugs,
311
- } = await loadSite();
327
+ const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
328
+ await loadSite();
312
329
 
313
330
  const versionsMetadata = readVersionsMetadata({
314
331
  options: defaultOptions,
@@ -319,13 +336,8 @@ describe('versioned site, pluginId=default', () => {
319
336
  });
320
337
 
321
338
  test('readVersionsMetadata versioned site with includeCurrentVersion=false', async () => {
322
- const {
323
- defaultOptions,
324
- defaultContext,
325
- v101,
326
- v100,
327
- vwithSlugs,
328
- } = await loadSite();
339
+ const {defaultOptions, defaultContext, v101, v100, vwithSlugs} =
340
+ await loadSite();
329
341
 
330
342
  const versionsMetadata = readVersionsMetadata({
331
343
  options: {...defaultOptions, includeCurrentVersion: false},
@@ -341,14 +353,8 @@ describe('versioned site, pluginId=default', () => {
341
353
  });
342
354
 
343
355
  test('readVersionsMetadata versioned site with version options', async () => {
344
- const {
345
- defaultOptions,
346
- defaultContext,
347
- vCurrent,
348
- v101,
349
- v100,
350
- vwithSlugs,
351
- } = await loadSite();
356
+ const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
357
+ await loadSite();
352
358
 
353
359
  const versionsMetadata = readVersionsMetadata({
354
360
  options: {
@@ -357,9 +363,13 @@ describe('versioned site, pluginId=default', () => {
357
363
  versions: {
358
364
  current: {
359
365
  path: 'current-path',
366
+ banner: 'unmaintained',
367
+ badge: false,
368
+ className: 'custom-current-className',
360
369
  },
361
370
  '1.0.0': {
362
371
  label: '1.0.0-label',
372
+ banner: 'unreleased',
363
373
  },
364
374
  },
365
375
  },
@@ -367,38 +377,43 @@ describe('versioned site, pluginId=default', () => {
367
377
  });
368
378
 
369
379
  expect(versionsMetadata).toEqual([
370
- {...vCurrent, versionPath: '/docs/current-path'},
380
+ {
381
+ ...vCurrent,
382
+ tagsPath: '/docs/current-path/tags',
383
+ versionPath: '/docs/current-path',
384
+ versionBanner: 'unmaintained',
385
+ versionBadge: false,
386
+ versionClassName: 'custom-current-className',
387
+ },
371
388
  {
372
389
  ...v101,
373
390
  isLast: false,
374
391
  routePriority: undefined,
392
+ tagsPath: '/docs/1.0.1/tags',
375
393
  versionPath: '/docs/1.0.1',
394
+ versionBanner: 'unreleased',
376
395
  },
377
396
  {
378
397
  ...v100,
379
398
  isLast: true,
380
399
  routePriority: -1,
400
+ tagsPath: '/docs/tags',
381
401
  versionLabel: '1.0.0-label',
382
402
  versionPath: '/docs',
403
+ versionBanner: 'unreleased',
383
404
  },
384
405
  vwithSlugs,
385
406
  ]);
386
407
  });
387
408
 
388
409
  test('readVersionsMetadata versioned site with editUrl', async () => {
389
- const {
390
- defaultOptions,
391
- defaultContext,
392
- vCurrent,
393
- v101,
394
- v100,
395
- vwithSlugs,
396
- } = await loadSite();
410
+ const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
411
+ await loadSite();
397
412
 
398
413
  const versionsMetadata = readVersionsMetadata({
399
414
  options: {
400
415
  ...defaultOptions,
401
- editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/',
416
+ editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/',
402
417
  },
403
418
  context: defaultContext,
404
419
  });
@@ -407,48 +422,42 @@ describe('versioned site, pluginId=default', () => {
407
422
  {
408
423
  ...vCurrent,
409
424
  versionEditUrl:
410
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
425
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
411
426
  versionEditUrlLocalized:
412
- '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',
413
428
  },
414
429
  {
415
430
  ...v101,
416
431
  versionEditUrl:
417
- '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',
418
433
  versionEditUrlLocalized:
419
- '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',
420
435
  },
421
436
  {
422
437
  ...v100,
423
438
  versionEditUrl:
424
- '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',
425
440
  versionEditUrlLocalized:
426
- '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',
427
442
  },
428
443
  {
429
444
  ...vwithSlugs,
430
445
  versionEditUrl:
431
- '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',
432
447
  versionEditUrlLocalized:
433
- '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',
434
449
  },
435
450
  ]);
436
451
  });
437
452
 
438
453
  test('readVersionsMetadata versioned site with editUrl and editCurrentVersion=true', async () => {
439
- const {
440
- defaultOptions,
441
- defaultContext,
442
- vCurrent,
443
- v101,
444
- v100,
445
- vwithSlugs,
446
- } = await loadSite();
454
+ const {defaultOptions, defaultContext, vCurrent, v101, v100, vwithSlugs} =
455
+ await loadSite();
447
456
 
448
457
  const versionsMetadata = readVersionsMetadata({
449
458
  options: {
450
459
  ...defaultOptions,
451
- editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/',
460
+ editUrl: 'https://github.com/facebook/docusaurus/edit/main/website/',
452
461
  editCurrentVersion: true,
453
462
  },
454
463
  context: defaultContext,
@@ -458,30 +467,30 @@ describe('versioned site, pluginId=default', () => {
458
467
  {
459
468
  ...vCurrent,
460
469
  versionEditUrl:
461
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
470
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
462
471
  versionEditUrlLocalized:
463
- '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',
464
473
  },
465
474
  {
466
475
  ...v101,
467
476
  versionEditUrl:
468
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
477
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
469
478
  versionEditUrlLocalized:
470
- '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',
471
480
  },
472
481
  {
473
482
  ...v100,
474
483
  versionEditUrl:
475
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
484
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
476
485
  versionEditUrlLocalized:
477
- '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',
478
487
  },
479
488
  {
480
489
  ...vwithSlugs,
481
490
  versionEditUrl:
482
- 'https://github.com/facebook/docusaurus/edit/master/website/docs',
491
+ 'https://github.com/facebook/docusaurus/edit/main/website/docs',
483
492
  versionEditUrlLocalized:
484
- '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',
485
494
  },
486
495
  ]);
487
496
  });
@@ -510,7 +519,15 @@ describe('versioned site, pluginId=default', () => {
510
519
  });
511
520
 
512
521
  expect(versionsMetadata).toEqual([
513
- {...vCurrent, isLast: true, routePriority: -1, versionPath: '/docs'},
522
+ {
523
+ ...vCurrent,
524
+ isLast: true,
525
+ routePriority: -1,
526
+ tagsPath: '/docs/tags',
527
+ versionPath: '/docs',
528
+ versionBanner: null,
529
+ versionBadge: false,
530
+ },
514
531
  ]);
515
532
  });
516
533
 
@@ -628,9 +645,13 @@ describe('versioned site, pluginId=community', () => {
628
645
  isLast: false,
629
646
  routePriority: undefined,
630
647
  sidebarFilePath: path.join(versionedSiteDir, 'sidebars.json'),
648
+ tagsPath: '/communityBasePath/next/tags',
631
649
  versionLabel: 'Next',
632
650
  versionName: 'current',
633
651
  versionPath: '/communityBasePath/next',
652
+ versionBanner: 'unreleased',
653
+ versionBadge: true,
654
+ versionClassName: 'docs-version-current',
634
655
  };
635
656
 
636
657
  const v100: VersionMetadata = {
@@ -648,9 +669,13 @@ describe('versioned site, pluginId=community', () => {
648
669
  versionedSiteDir,
649
670
  'community_versioned_sidebars/version-1.0.0-sidebars.json',
650
671
  ),
672
+ tagsPath: '/communityBasePath/tags',
651
673
  versionLabel: '1.0.0',
652
674
  versionName: '1.0.0',
653
675
  versionPath: '/communityBasePath',
676
+ versionBanner: null,
677
+ versionBadge: true,
678
+ versionClassName: 'docs-version-1.0.0',
654
679
  };
655
680
 
656
681
  return {versionedSiteDir, defaultOptions, defaultContext, vCurrent, v100};
@@ -677,7 +702,7 @@ describe('versioned site, pluginId=community', () => {
677
702
 
678
703
  expect(versionsMetadata).toEqual([
679
704
  // vCurrent removed
680
- v100,
705
+ {...v100, versionBadge: false},
681
706
  ]);
682
707
  });
683
708
 
@@ -694,7 +719,10 @@ describe('versioned site, pluginId=community', () => {
694
719
  ...vCurrent,
695
720
  isLast: true,
696
721
  routePriority: -1,
722
+ tagsPath: '/communityBasePath/tags',
697
723
  versionPath: '/communityBasePath',
724
+ versionBanner: null,
725
+ versionBadge: false,
698
726
  },
699
727
  ]);
700
728
  });
package/src/cli.ts CHANGED
@@ -12,12 +12,10 @@ 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';
15
+ import type {PathOptions, SidebarOptions} from './types';
16
+ import {transformSidebarItems} from './sidebars/utils';
17
+ import type {SidebarItem, NormalizedSidebars, Sidebar} from './sidebars/types';
18
+ import {loadUnprocessedSidebars, resolveSidebarPathOption} from './sidebars';
21
19
  import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
22
20
 
23
21
  function createVersionedSidebarFile({
@@ -25,14 +23,16 @@ function createVersionedSidebarFile({
25
23
  pluginId,
26
24
  sidebarPath,
27
25
  version,
26
+ options,
28
27
  }: {
29
28
  siteDir: string;
30
29
  pluginId: string;
31
30
  sidebarPath: string | false | undefined;
32
31
  version: string;
32
+ options: SidebarOptions;
33
33
  }) {
34
34
  // Load current sidebar and create a new versioned sidebars file (if needed).
35
- const loadedSidebars = loadSidebars(sidebarPath);
35
+ const loadedSidebars = loadUnprocessedSidebars(sidebarPath, options);
36
36
 
37
37
  // Do not create a useless versioned sidebars file if sidebars file is empty or sidebars are disabled/false)
38
38
  const shouldCreateVersionedSidebarFile =
@@ -42,30 +42,27 @@ function createVersionedSidebarFile({
42
42
  // TODO @slorber: this "version prefix" in versioned sidebars looks like a bad idea to me
43
43
  // TODO try to get rid of it
44
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;
45
+ const prependVersion = (item: SidebarItem): SidebarItem => {
46
+ if (item.type === 'ref' || item.type === 'doc') {
47
+ return {
48
+ type: item.type,
49
+ id: `version-${version}/${item.id}`,
50
+ };
59
51
  }
52
+ return item;
60
53
  };
61
54
 
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
- }, {});
55
+ const versionedSidebar = Object.entries(loadedSidebars).reduce(
56
+ (acc: NormalizedSidebars, [sidebarId, sidebar]) => {
57
+ const versionedId = `version-${version}/${sidebarId}`;
58
+ acc[versionedId] = transformSidebarItems(
59
+ sidebar as Sidebar,
60
+ prependVersion,
61
+ );
62
+ return acc;
63
+ },
64
+ {},
65
+ );
69
66
 
70
67
  const versionedSidebarsDir = getVersionedSidebarsDirPath(siteDir, pluginId);
71
68
  const newSidebarFile = path.join(
@@ -82,12 +79,11 @@ function createVersionedSidebarFile({
82
79
  }
83
80
 
84
81
  // Tests depend on non-default export for mocking.
85
- // eslint-disable-next-line import/prefer-default-export
86
82
  export function cliDocsVersionCommand(
87
83
  version: string | null | undefined,
88
84
  siteDir: string,
89
85
  pluginId: string,
90
- options: PathOptions,
86
+ options: PathOptions & SidebarOptions,
91
87
  ): void {
92
88
  // It wouldn't be very user-friendly to show a [default] log prefix,
93
89
  // so we use [docs] instead of [default]
@@ -159,6 +155,7 @@ export function cliDocsVersionCommand(
159
155
  pluginId,
160
156
  version,
161
157
  sidebarPath: resolveSidebarPathOption(siteDir, sidebarPath),
158
+ options,
162
159
  });
163
160
 
164
161
  // Update versions.json file.
@@ -350,14 +350,13 @@ describe('docsClientUtils', () => {
350
350
  latestVersionSuggestion: version2,
351
351
  });
352
352
 
353
- // nothing to suggest, we are already on latest version
354
353
  expect(getDocVersionSuggestions(data, '/docs/')).toEqual({
355
- latestDocSuggestion: undefined,
356
- latestVersionSuggestion: undefined,
354
+ latestDocSuggestion: version2.docs[0],
355
+ latestVersionSuggestion: version2,
357
356
  });
358
357
  expect(getDocVersionSuggestions(data, '/docs/doc2')).toEqual({
359
- latestDocSuggestion: undefined,
360
- latestVersionSuggestion: undefined,
358
+ latestDocSuggestion: version2.docs[1],
359
+ latestVersionSuggestion: version2,
361
360
  });
362
361
 
363
362
  expect(getDocVersionSuggestions(data, '/docs/version1/')).toEqual({
@@ -20,22 +20,11 @@ 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,
@@ -140,10 +129,10 @@ export const getActiveDocContext = (
140
129
  };
141
130
 
142
131
  export type DocVersionSuggestions = {
132
+ // suggest the latest version
133
+ latestVersionSuggestion: GlobalVersion;
143
134
  // suggest the same doc, in latest version (if exist)
144
135
  latestDocSuggestion?: GlobalDoc;
145
- // suggest the latest version
146
- latestVersionSuggestion?: GlobalVersion;
147
136
  };
148
137
 
149
138
  export const getDocVersionSuggestions = (
@@ -152,17 +141,7 @@ export const getDocVersionSuggestions = (
152
141
  ): DocVersionSuggestions => {
153
142
  const latestVersion = getLatestVersion(data);
154
143
  const activeDocContext = getActiveDocContext(data, pathname);
155
-
156
- // We only suggest another doc/version if user is not using the latest version
157
- const isNotOnLatestVersion = activeDocContext.activeVersion !== latestVersion;
158
-
159
- const latestDocSuggestion: GlobalDoc | undefined = isNotOnLatestVersion
160
- ? activeDocContext?.alternateDocVersions[latestVersion.name]
161
- : undefined;
162
-
163
- const latestVersionSuggestion = isNotOnLatestVersion
164
- ? latestVersion
165
- : undefined;
166
-
167
- return {latestDocSuggestion, latestVersionSuggestion};
144
+ const latestDocSuggestion: GlobalDoc | undefined =
145
+ activeDocContext?.alternateDocVersions[latestVersion.name];
146
+ return {latestDocSuggestion, latestVersionSuggestion: latestVersion};
168
147
  };
@@ -5,11 +5,11 @@
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
15
  import {DocFrontMatter} from './types';
@@ -28,10 +28,15 @@ const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
28
28
  description: Joi.string().allow(''), // see https://github.com/facebook/docusaurus/issues/4591#issuecomment-822372398
29
29
  slug: Joi.string(),
30
30
  sidebar_label: Joi.string(),
31
- sidebar_position: Joi.number().min(0),
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(