@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
@@ -5,8 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
9
-
10
8
  import path from 'path';
11
9
  import {isMatch} from 'picomatch';
12
10
  import commander from 'commander';
@@ -24,17 +22,16 @@ import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
24
22
  import * as cliDocs from '../cli';
25
23
  import {OptionsSchema} from '../options';
26
24
  import {normalizePluginOptions} from '@docusaurus/utils-validation';
27
- import {
28
- DocMetadata,
29
- LoadedVersion,
25
+ import type {DocMetadata, LoadedVersion} from '../types';
26
+ import type {
30
27
  SidebarItem,
31
28
  SidebarItemsGeneratorOption,
32
29
  SidebarItemsGeneratorOptionArgs,
33
- } from '../types';
30
+ } from '../sidebars/types';
34
31
  import {toSidebarsProp} from '../props';
35
32
 
36
33
  import {validate} from 'webpack';
37
- import {DefaultSidebarItemsGenerator} from '../sidebarItemsGenerator';
34
+ import {DefaultSidebarItemsGenerator} from '../sidebars/generator';
38
35
  import {DisabledSidebars} from '../sidebars';
39
36
 
40
37
  function findDocById(version: LoadedVersion, unversionedId: string) {
@@ -60,6 +57,7 @@ const defaultDocMetadata: Partial<DocMetadata> = {
60
57
  lastUpdatedAt: undefined,
61
58
  lastUpdatedBy: undefined,
62
59
  formattedLastUpdatedAt: undefined,
60
+ tags: [],
63
61
  };
64
62
 
65
63
  const createFakeActions = (contentDir: string) => {
@@ -105,9 +103,6 @@ Entries created:
105
103
  `version-${kebabCase(version.versionName)}-metadata-prop`,
106
104
  );
107
105
  expect(versionMetadataProp.docsSidebars).toEqual(toSidebarsProp(version));
108
- expect(versionMetadataProp.permalinkToSidebar).toEqual(
109
- version.permalinkToSidebar,
110
- );
111
106
  },
112
107
 
113
108
  expectSnapshot: () => {
@@ -273,6 +268,8 @@ describe('simple website', () => {
273
268
  expect(mock).toHaveBeenCalledWith('1.0.0', siteDir, DEFAULT_PLUGIN_ID, {
274
269
  path: 'docs',
275
270
  sidebarPath,
271
+ sidebarCollapsed: true,
272
+ sidebarCollapsible: true,
276
273
  });
277
274
  mock.mockRestore();
278
275
  });
@@ -309,6 +306,8 @@ describe('simple website', () => {
309
306
  test('configureWebpack', async () => {
310
307
  const {plugin} = await loadSite();
311
308
 
309
+ const content = await plugin.loadContent?.();
310
+
312
311
  const config = applyConfigureWebpack(
313
312
  plugin.configureWebpack,
314
313
  {
@@ -319,6 +318,8 @@ describe('simple website', () => {
319
318
  },
320
319
  },
321
320
  false,
321
+ undefined,
322
+ content,
322
323
  );
323
324
  const errors = validate(config);
324
325
  expect(errors).toBeUndefined();
@@ -344,10 +345,11 @@ describe('simple website', () => {
344
345
  permalink: '/docs/foo/bar',
345
346
  },
346
347
  next: {
347
- title: 'Hello sidebar_label',
348
- permalink: '/docs/',
348
+ title: 'rootAbsoluteSlug',
349
+ permalink: '/docs/rootAbsoluteSlug',
349
350
  },
350
351
  sidebar: 'docs',
352
+ sidebarPosition: undefined,
351
353
  source: path.posix.join(
352
354
  '@site',
353
355
  posixPath(path.relative(siteDir, currentVersion.contentPath)),
@@ -361,7 +363,23 @@ describe('simple website', () => {
361
363
  title: 'baz',
362
364
  slug: 'bazSlug.html',
363
365
  pagination_label: 'baz pagination_label',
366
+ tags: [
367
+ 'tag 1',
368
+ 'tag-1', // This one will be de-duplicated as it would lead to the same permalink as the first
369
+ {label: 'tag 2', permalink: 'tag2-custom-permalink'},
370
+ ],
364
371
  },
372
+
373
+ tags: [
374
+ {
375
+ label: 'tag 1',
376
+ permalink: '/docs/tags/tag-1',
377
+ },
378
+ {
379
+ label: 'tag 2',
380
+ permalink: '/docs/tags/tag2-custom-permalink',
381
+ },
382
+ ],
365
383
  });
366
384
 
367
385
  expect(findDocById(currentVersion, 'hello')).toEqual({
@@ -374,8 +392,8 @@ describe('simple website', () => {
374
392
  permalink: '/docs/',
375
393
  slug: '/',
376
394
  previous: {
377
- title: 'baz pagination_label',
378
- permalink: '/docs/foo/bazSlug.html',
395
+ title: 'My heading as title',
396
+ permalink: '/docs/headingAsTitle',
379
397
  },
380
398
  sidebar: 'docs',
381
399
  source: path.posix.join(
@@ -389,7 +407,18 @@ describe('simple website', () => {
389
407
  id: 'hello',
390
408
  title: 'Hello, World !',
391
409
  sidebar_label: 'Hello sidebar_label',
410
+ tags: ['tag-1', 'tag 3'],
392
411
  },
412
+ tags: [
413
+ {
414
+ label: 'tag-1',
415
+ permalink: '/docs/tags/tag-1',
416
+ },
417
+ {
418
+ label: 'tag 3',
419
+ permalink: '/docs/tags/tag-3',
420
+ },
421
+ ],
393
422
  });
394
423
 
395
424
  expect(getDocById(currentVersion, 'foo/bar')).toEqual({
@@ -477,6 +506,8 @@ describe('versioned website', () => {
477
506
  expect(mock).toHaveBeenCalledWith('2.0.0', siteDir, DEFAULT_PLUGIN_ID, {
478
507
  path: routeBasePath,
479
508
  sidebarPath,
509
+ sidebarCollapsed: true,
510
+ sidebarCollapsible: true,
480
511
  });
481
512
  mock.mockRestore();
482
513
  });
@@ -544,12 +575,8 @@ describe('versioned website', () => {
544
575
  const {siteDir, plugin, pluginContentDir} = await loadSite();
545
576
  const content = await plugin.loadContent!();
546
577
  expect(content.loadedVersions.length).toEqual(4);
547
- const [
548
- currentVersion,
549
- version101,
550
- version100,
551
- versionWithSlugs,
552
- ] = content.loadedVersions;
578
+ const [currentVersion, version101, version100, versionWithSlugs] =
579
+ content.loadedVersions;
553
580
 
554
581
  // foo/baz.md only exists in version -1.0.0
555
582
  expect(findDocById(currentVersion, 'foo/baz')).toBeUndefined();
@@ -574,6 +601,11 @@ describe('versioned website', () => {
574
601
  description: 'This is next version of bar.',
575
602
  frontMatter: {
576
603
  slug: 'barSlug',
604
+ tags: [
605
+ 'barTag 1',
606
+ 'barTag-2',
607
+ {label: 'barTag 3', permalink: 'barTag-3-permalink'},
608
+ ],
577
609
  },
578
610
  version: 'current',
579
611
  sidebar: 'docs',
@@ -581,6 +613,11 @@ describe('versioned website', () => {
581
613
  title: 'hello',
582
614
  permalink: '/docs/next/',
583
615
  },
616
+ tags: [
617
+ {label: 'barTag 1', permalink: '/docs/next/tags/bar-tag-1'},
618
+ {label: 'barTag-2', permalink: '/docs/next/tags/bar-tag-2'},
619
+ {label: 'barTag 3', permalink: '/docs/next/tags/barTag-3-permalink'},
620
+ ],
584
621
  });
585
622
  expect(getDocById(currentVersion, 'hello')).toEqual({
586
623
  ...defaultDocMetadata,
@@ -710,13 +747,8 @@ describe('versioned website (community)', () => {
710
747
  }
711
748
 
712
749
  test('extendCli - docsVersion', async () => {
713
- const {
714
- siteDir,
715
- routeBasePath,
716
- sidebarPath,
717
- pluginId,
718
- plugin,
719
- } = await loadSite();
750
+ const {siteDir, routeBasePath, sidebarPath, pluginId, plugin} =
751
+ await loadSite();
720
752
  const mock = jest
721
753
  .spyOn(cliDocs, 'cliDocsVersionCommand')
722
754
  .mockImplementation();
@@ -728,6 +760,8 @@ describe('versioned website (community)', () => {
728
760
  expect(mock).toHaveBeenCalledWith('2.0.0', siteDir, pluginId, {
729
761
  path: routeBasePath,
730
762
  sidebarPath,
763
+ sidebarCollapsed: true,
764
+ sidebarCollapsible: true,
731
765
  });
732
766
  mock.mockRestore();
733
767
  });
@@ -906,6 +940,7 @@ describe('site with full autogenerated sidebar', () => {
906
940
  type: 'category',
907
941
  label: 'Guides',
908
942
  collapsed: true,
943
+ collapsible: true,
909
944
  items: [
910
945
  {
911
946
  type: 'doc',
@@ -937,6 +972,7 @@ describe('site with full autogenerated sidebar', () => {
937
972
  type: 'category',
938
973
  label: 'API (label from _category_.json)',
939
974
  collapsed: true,
975
+ collapsible: true,
940
976
  items: [
941
977
  {
942
978
  type: 'doc',
@@ -946,6 +982,7 @@ describe('site with full autogenerated sidebar', () => {
946
982
  type: 'category',
947
983
  label: 'Core APIs',
948
984
  collapsed: true,
985
+ collapsible: true,
949
986
  items: [
950
987
  {
951
988
  type: 'doc',
@@ -962,6 +999,7 @@ describe('site with full autogenerated sidebar', () => {
962
999
  type: 'category',
963
1000
  label: 'Extension APIs (label from _category_.yml)',
964
1001
  collapsed: true,
1002
+ collapsible: true,
965
1003
  items: [
966
1004
  {
967
1005
  type: 'doc',
@@ -1460,6 +1498,7 @@ describe('site with partial autogenerated sidebars', () => {
1460
1498
  type: 'category',
1461
1499
  label: 'Some category',
1462
1500
  collapsed: true,
1501
+ collapsible: true,
1463
1502
  items: [
1464
1503
  {
1465
1504
  type: 'doc',
@@ -1649,6 +1688,7 @@ describe('site with partial autogenerated sidebars 2 (fix #4638)', () => {
1649
1688
  type: 'category',
1650
1689
  label: 'Core APIs',
1651
1690
  collapsed: true,
1691
+ collapsible: true,
1652
1692
  items: [
1653
1693
  {
1654
1694
  type: 'doc',
@@ -1665,6 +1705,7 @@ describe('site with partial autogenerated sidebars 2 (fix #4638)', () => {
1665
1705
  type: 'category',
1666
1706
  label: 'Extension APIs (label from _category_.yml)', // Fix #4638
1667
1707
  collapsed: true,
1708
+ collapsible: true,
1668
1709
  items: [
1669
1710
  {
1670
1711
  type: 'doc',
@@ -1734,12 +1775,11 @@ describe('site with custom sidebar items generator', () => {
1734
1775
  });
1735
1776
 
1736
1777
  test('sidebar is autogenerated according to a custom sidebarItemsGenerator', async () => {
1737
- const customSidebarItemsGenerator: SidebarItemsGeneratorOption = async () => {
1738
- return [
1778
+ const customSidebarItemsGenerator: SidebarItemsGeneratorOption =
1779
+ async () => [
1739
1780
  {type: 'doc', id: 'API/api-overview'},
1740
1781
  {type: 'doc', id: 'API/api-end'},
1741
1782
  ];
1742
- };
1743
1783
 
1744
1784
  const {content} = await loadSite(customSidebarItemsGenerator);
1745
1785
  const version = content.loadedVersions[0];
@@ -1781,6 +1821,7 @@ describe('site with custom sidebar items generator', () => {
1781
1821
  type: 'category',
1782
1822
  label: 'API (label from _category_.json)',
1783
1823
  collapsed: true,
1824
+ collapsible: true,
1784
1825
  items: [
1785
1826
  {
1786
1827
  type: 'doc',
@@ -1790,6 +1831,7 @@ describe('site with custom sidebar items generator', () => {
1790
1831
  type: 'category',
1791
1832
  label: 'Extension APIs (label from _category_.yml)',
1792
1833
  collapsed: true,
1834
+ collapsible: true,
1793
1835
  items: [
1794
1836
  {
1795
1837
  type: 'doc',
@@ -1805,6 +1847,7 @@ describe('site with custom sidebar items generator', () => {
1805
1847
  type: 'category',
1806
1848
  label: 'Core APIs',
1807
1849
  collapsed: true,
1850
+ collapsible: true,
1808
1851
  items: [
1809
1852
  {
1810
1853
  type: 'doc',
@@ -1826,6 +1869,7 @@ describe('site with custom sidebar items generator', () => {
1826
1869
  type: 'category',
1827
1870
  label: 'Guides',
1828
1871
  collapsed: true,
1872
+ collapsible: true,
1829
1873
  items: [
1830
1874
  {
1831
1875
  type: 'doc',
@@ -31,15 +31,16 @@ describe('lastUpdate', () => {
31
31
  test('non-existing file', async () => {
32
32
  const consoleMock = jest.spyOn(console, 'error');
33
33
  consoleMock.mockImplementation();
34
+ const nonExistingFileName = '.nonExisting';
34
35
  const nonExistingFilePath = path.join(
35
36
  __dirname,
36
37
  '__fixtures__',
37
- '.nonExisting',
38
+ nonExistingFileName,
38
39
  );
39
40
  expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull();
40
41
  expect(consoleMock).toHaveBeenCalledTimes(1);
41
42
  expect(consoleMock.mock.calls[0][0].message).toContain(
42
- `Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFilePath}`,
43
+ `Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFileName}`,
43
44
  );
44
45
  expect(await getFileLastUpdate(null)).toBeNull();
45
46
  expect(await getFileLastUpdate(undefined)).toBeNull();
@@ -5,18 +5,30 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import {OptionsSchema, DEFAULT_OPTIONS} from '../options';
8
+ import {OptionsSchema, DEFAULT_OPTIONS, validateOptions} from '../options';
9
9
  import {normalizePluginOptions} from '@docusaurus/utils-validation';
10
- import {DefaultSidebarItemsGenerator} from '../sidebarItemsGenerator';
10
+ import {DefaultSidebarItemsGenerator} from '../sidebars/generator';
11
11
  import {
12
12
  DefaultNumberPrefixParser,
13
13
  DisabledNumberPrefixParser,
14
14
  } from '../numberPrefix';
15
+ import {GlobExcludeDefault} from '@docusaurus/utils';
16
+ import {PluginOptions} from '../types';
15
17
 
16
18
  // the type of remark/rehype plugins is function
17
19
  const markdownPluginsFunctionStub = () => {};
18
20
  const markdownPluginsObjectStub = {};
19
21
 
22
+ function testValidateOptions(options: Partial<PluginOptions>) {
23
+ return validateOptions({
24
+ options: {
25
+ ...DEFAULT_OPTIONS,
26
+ ...options,
27
+ },
28
+ validate: normalizePluginOptions,
29
+ });
30
+ }
31
+
20
32
  describe('normalizeDocsPluginOptions', () => {
21
33
  test('should return default options for undefined user options', async () => {
22
34
  const {value, error} = await OptionsSchema.validate({});
@@ -28,13 +40,17 @@ describe('normalizeDocsPluginOptions', () => {
28
40
  const userOptions = {
29
41
  path: 'my-docs', // Path to data on filesystem, relative to site dir.
30
42
  routeBasePath: 'my-docs', // URL Route.
43
+ tagsBasePath: 'tags', // URL Tags Route.
31
44
  homePageId: 'home', // Document id for docs home page.
32
45
  include: ['**/*.{md,mdx}'], // Extensions to include.
46
+ exclude: GlobExcludeDefault,
33
47
  sidebarPath: 'my-sidebar', // Path to sidebar configuration for showing a list of markdown pages.
34
48
  sidebarItemsGenerator: DefaultSidebarItemsGenerator,
35
49
  numberPrefixParser: DefaultNumberPrefixParser,
36
50
  docLayoutComponent: '@theme/DocPage',
37
51
  docItemComponent: '@theme/DocItem',
52
+ docTagDocListComponent: '@theme/DocTagDocListPage',
53
+ docTagsListComponent: '@theme/DocTagsListPage',
38
54
  remarkPlugins: [markdownPluginsObjectStub],
39
55
  rehypePlugins: [markdownPluginsFunctionStub],
40
56
  beforeDefaultRehypePlugins: [],
@@ -42,7 +58,6 @@ describe('normalizeDocsPluginOptions', () => {
42
58
  showLastUpdateTime: true,
43
59
  showLastUpdateAuthor: true,
44
60
  admonitions: {},
45
- excludeNextVersionDocs: true,
46
61
  includeCurrentVersion: false,
47
62
  disableVersioning: true,
48
63
  editCurrentVersion: true,
@@ -57,6 +72,8 @@ describe('normalizeDocsPluginOptions', () => {
57
72
  label: 'world',
58
73
  },
59
74
  },
75
+ sidebarCollapsible: false,
76
+ sidebarCollapsed: false,
60
77
  };
61
78
  const {value, error} = await OptionsSchema.validate(userOptions);
62
79
  expect(value).toEqual(userOptions);
@@ -229,4 +246,30 @@ describe('normalizeDocsPluginOptions', () => {
229
246
  `"\\"versions.current.hey\\" is not allowed"`,
230
247
  );
231
248
  });
249
+
250
+ test('should handle sidebarCollapsed option inconsistencies', () => {
251
+ expect(
252
+ testValidateOptions({
253
+ ...DEFAULT_OPTIONS,
254
+ sidebarCollapsible: true,
255
+ sidebarCollapsed: undefined,
256
+ }).sidebarCollapsed,
257
+ ).toEqual(true);
258
+
259
+ expect(
260
+ testValidateOptions({
261
+ ...DEFAULT_OPTIONS,
262
+ sidebarCollapsible: false,
263
+ sidebarCollapsed: undefined,
264
+ }).sidebarCollapsed,
265
+ ).toEqual(false);
266
+
267
+ expect(
268
+ testValidateOptions({
269
+ ...DEFAULT_OPTIONS,
270
+ sidebarCollapsible: false,
271
+ sidebarCollapsed: true,
272
+ }).sidebarCollapsed,
273
+ ).toEqual(false);
274
+ });
232
275
  });
@@ -0,0 +1,62 @@
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 {toTagDocListProp} from '../props';
9
+
10
+ describe('toTagDocListProp', () => {
11
+ type Params = Parameters<typeof toTagDocListProp>[0];
12
+ type Tag = Params['tag'];
13
+ type Doc = Params['docs'][number];
14
+
15
+ const allTagsPath = '/all/tags';
16
+
17
+ test('should work', () => {
18
+ const tag: Tag = {
19
+ name: 'tag1',
20
+ permalink: '/tag1',
21
+ docIds: ['id1', 'id3'],
22
+ };
23
+
24
+ const doc1: Doc = {
25
+ id: 'id1',
26
+ title: 'ZZZ 1',
27
+ description: 'Description 1',
28
+ permalink: '/doc1',
29
+ };
30
+ const doc2: Doc = {
31
+ id: 'id2',
32
+ title: 'XXX 2',
33
+ description: 'Description 2',
34
+ permalink: '/doc2',
35
+ };
36
+ const doc3: Doc = {
37
+ id: 'id3',
38
+ title: 'AAA 3',
39
+ description: 'Description 3',
40
+ permalink: '/doc3',
41
+ };
42
+ const doc4: Doc = {
43
+ id: 'id4',
44
+ title: 'UUU 4',
45
+ description: 'Description 4',
46
+ permalink: '/doc4',
47
+ };
48
+
49
+ const result = toTagDocListProp({
50
+ allTagsPath,
51
+ tag,
52
+ docs: [doc1, doc2, doc3, doc4],
53
+ });
54
+
55
+ expect(result).toEqual({
56
+ allTagsPath,
57
+ name: tag.name,
58
+ permalink: tag.permalink,
59
+ docs: [doc3, doc1], // docs sorted by title, ignore "id5" absence
60
+ });
61
+ });
62
+ });
@@ -40,7 +40,6 @@ function createSampleVersion(
40
40
  versionLabel: `${version.versionName} label`,
41
41
  versionPath: '/docs/',
42
42
  mainDocId: '',
43
- permalinkToSidebar: {},
44
43
  routePriority: undefined,
45
44
  sidebarFilePath: 'any',
46
45
  isLast: true,