@docusaurus/plugin-content-docs 2.0.0-beta.0e652730d → 2.0.0-beta.10

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 (140) 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 +1 -4
  7. package/lib/client/docsClientUtils.js +21 -31
  8. package/lib/docFrontMatter.d.ts +1 -1
  9. package/lib/docFrontMatter.js +10 -6
  10. package/lib/docs.d.ts +25 -3
  11. package/lib/docs.js +125 -38
  12. package/lib/globalData.d.ts +1 -1
  13. package/lib/index.d.ts +1 -1
  14. package/lib/index.js +104 -138
  15. package/lib/lastUpdate.js +9 -10
  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 +49 -17
  22. package/lib/props.d.ts +7 -2
  23. package/lib/props.js +61 -9
  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 +24 -21
  45. package/lib/translations.d.ts +2 -2
  46. package/lib/translations.js +71 -29
  47. package/lib/types.d.ts +52 -62
  48. package/lib/versions.d.ts +3 -3
  49. package/lib/versions.js +76 -24
  50. package/package.json +22 -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 +753 -112
  75. package/src/__tests__/__snapshots__/translations.test.ts.snap +45 -18
  76. package/src/__tests__/cli.test.ts +15 -11
  77. package/src/__tests__/docFrontMatter.test.ts +195 -40
  78. package/src/__tests__/docs.test.ts +311 -150
  79. package/src/__tests__/index.test.ts +112 -69
  80. package/src/__tests__/lastUpdate.test.ts +3 -2
  81. package/src/__tests__/options.test.ts +48 -4
  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 -2
  85. package/src/__tests__/versions.test.ts +93 -67
  86. package/src/categoryGeneratedIndex.ts +57 -0
  87. package/src/cli.ts +8 -41
  88. package/src/client/__tests__/docsClientUtils.test.ts +4 -5
  89. package/src/client/docsClientUtils.ts +19 -41
  90. package/{types.d.ts → src/deps.d.ts} +0 -0
  91. package/src/docFrontMatter.ts +13 -7
  92. package/src/docs.ts +158 -29
  93. package/src/globalData.ts +6 -1
  94. package/src/index.ts +134 -179
  95. package/src/lastUpdate.ts +10 -9
  96. package/src/markdown/index.ts +8 -12
  97. package/src/numberPrefix.ts +5 -3
  98. package/src/options.ts +59 -28
  99. package/src/plugin-content-docs.d.ts +179 -35
  100. package/src/props.ts +91 -16
  101. package/src/routes.ts +173 -0
  102. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
  103. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
  104. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
  105. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
  106. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
  107. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
  108. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
  109. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
  110. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
  111. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
  112. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
  113. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
  114. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
  115. package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
  116. package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +36 -6
  117. package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +143 -18
  118. package/src/sidebars/__tests__/index.test.ts +204 -0
  119. package/src/sidebars/__tests__/processor.test.ts +237 -0
  120. package/src/sidebars/__tests__/utils.test.ts +695 -0
  121. package/src/sidebars/__tests__/validation.test.ts +105 -0
  122. package/src/sidebars/generator.ts +310 -0
  123. package/src/sidebars/index.ts +94 -0
  124. package/src/sidebars/normalization.ts +112 -0
  125. package/src/sidebars/processor.ts +154 -0
  126. package/src/sidebars/types.ts +211 -0
  127. package/src/sidebars/utils.ts +329 -0
  128. package/src/sidebars/validation.ts +168 -0
  129. package/src/slug.ts +32 -17
  130. package/src/tags.ts +19 -0
  131. package/src/theme/hooks/useDocs.ts +5 -1
  132. package/src/translations.ts +103 -47
  133. package/src/types.ts +67 -105
  134. package/src/versions.ts +117 -21
  135. package/lib/sidebarItemsGenerator.js +0 -211
  136. package/lib/sidebars.d.ts +0 -43
  137. package/lib/sidebars.js +0 -319
  138. package/src/__tests__/sidebars.test.ts +0 -639
  139. package/src/sidebarItemsGenerator.ts +0 -307
  140. package/src/sidebars.ts +0 -506
@@ -13,14 +13,15 @@ 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',
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
 
@@ -583,11 +600,9 @@ describe('versioned site, pluginId=default', () => {
583
600
  test('readVersionsMetadata versioned site with invalid versions.json file', async () => {
584
601
  const {defaultOptions, defaultContext} = await loadSite();
585
602
 
586
- const mock = jest.spyOn(JSON, 'parse').mockImplementationOnce(() => {
587
- return {
588
- invalid: 'json',
589
- };
590
- });
603
+ const mock = jest.spyOn(JSON, 'parse').mockImplementationOnce(() => ({
604
+ invalid: 'json',
605
+ }));
591
606
 
592
607
  expect(() => {
593
608
  readVersionsMetadata({
@@ -628,9 +643,13 @@ describe('versioned site, pluginId=community', () => {
628
643
  isLast: false,
629
644
  routePriority: undefined,
630
645
  sidebarFilePath: path.join(versionedSiteDir, 'sidebars.json'),
646
+ tagsPath: '/communityBasePath/next/tags',
631
647
  versionLabel: 'Next',
632
648
  versionName: 'current',
633
649
  versionPath: '/communityBasePath/next',
650
+ versionBanner: 'unreleased',
651
+ versionBadge: true,
652
+ versionClassName: 'docs-version-current',
634
653
  };
635
654
 
636
655
  const v100: VersionMetadata = {
@@ -648,9 +667,13 @@ describe('versioned site, pluginId=community', () => {
648
667
  versionedSiteDir,
649
668
  'community_versioned_sidebars/version-1.0.0-sidebars.json',
650
669
  ),
670
+ tagsPath: '/communityBasePath/tags',
651
671
  versionLabel: '1.0.0',
652
672
  versionName: '1.0.0',
653
673
  versionPath: '/communityBasePath',
674
+ versionBanner: null,
675
+ versionBadge: true,
676
+ versionClassName: 'docs-version-1.0.0',
654
677
  };
655
678
 
656
679
  return {versionedSiteDir, defaultOptions, defaultContext, vCurrent, v100};
@@ -677,7 +700,7 @@ describe('versioned site, pluginId=community', () => {
677
700
 
678
701
  expect(versionsMetadata).toEqual([
679
702
  // vCurrent removed
680
- v100,
703
+ {...v100, versionBadge: false},
681
704
  ]);
682
705
  });
683
706
 
@@ -694,7 +717,10 @@ describe('versioned site, pluginId=community', () => {
694
717
  ...vCurrent,
695
718
  isLast: true,
696
719
  routePriority: -1,
720
+ tagsPath: '/communityBasePath/tags',
697
721
  versionPath: '/communityBasePath',
722
+ versionBanner: null,
723
+ versionBadge: false,
698
724
  },
699
725
  ]);
700
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]
@@ -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,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 = (
@@ -140,10 +128,10 @@ export const getActiveDocContext = (
140
128
  };
141
129
 
142
130
  export type DocVersionSuggestions = {
131
+ // suggest the latest version
132
+ latestVersionSuggestion: GlobalVersion;
143
133
  // suggest the same doc, in latest version (if exist)
144
134
  latestDocSuggestion?: GlobalDoc;
145
- // suggest the latest version
146
- latestVersionSuggestion?: GlobalVersion;
147
135
  };
148
136
 
149
137
  export const getDocVersionSuggestions = (
@@ -152,17 +140,7 @@ export const getDocVersionSuggestions = (
152
140
  ): DocVersionSuggestions => {
153
141
  const latestVersion = getLatestVersion(data);
154
142
  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};
143
+ const latestDocSuggestion: GlobalDoc | undefined =
144
+ activeDocContext?.alternateDocVersions[latestVersion.name];
145
+ return {latestDocSuggestion, latestVersionSuggestion: latestVersion};
168
146
  };
File without changes