@docusaurus/plugin-content-docs 2.0.0-beta.1 → 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.
- package/lib/.tsbuildinfo +1 -1
- package/lib/categoryGeneratedIndex.d.ts +12 -0
- package/lib/categoryGeneratedIndex.js +37 -0
- package/lib/cli.d.ts +2 -2
- package/lib/cli.js +12 -34
- package/lib/client/docsClientUtils.d.ts +1 -4
- package/lib/client/docsClientUtils.js +21 -31
- package/lib/docFrontMatter.d.ts +1 -1
- package/lib/docFrontMatter.js +10 -6
- package/lib/docs.d.ts +25 -3
- package/lib/docs.js +125 -38
- package/lib/globalData.d.ts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +104 -138
- package/lib/lastUpdate.js +9 -10
- package/lib/markdown/index.d.ts +3 -6
- package/lib/markdown/index.js +3 -3
- package/lib/markdown/linkify.js +2 -2
- package/lib/numberPrefix.d.ts +1 -1
- package/lib/options.d.ts +3 -3
- package/lib/options.js +49 -17
- package/lib/props.d.ts +7 -2
- package/lib/props.js +61 -9
- package/lib/routes.d.ts +27 -0
- package/lib/routes.js +105 -0
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +5 -2
- package/lib/sidebars/generator.js +216 -0
- package/lib/sidebars/index.d.ts +15 -0
- package/lib/sidebars/index.js +73 -0
- package/lib/sidebars/normalization.d.ts +14 -0
- package/lib/sidebars/normalization.js +77 -0
- package/lib/sidebars/processor.d.ts +18 -0
- package/lib/sidebars/processor.js +85 -0
- package/lib/sidebars/types.d.ts +127 -0
- package/lib/sidebars/types.js +8 -0
- package/lib/sidebars/utils.d.ts +35 -0
- package/lib/sidebars/utils.js +228 -0
- package/lib/sidebars/validation.d.ts +10 -0
- package/lib/sidebars/validation.js +138 -0
- package/lib/slug.d.ts +4 -3
- package/lib/slug.js +27 -15
- package/lib/tags.d.ts +8 -0
- package/lib/tags.js +20 -0
- package/lib/theme/hooks/useDocs.js +24 -21
- package/lib/translations.d.ts +2 -2
- package/lib/translations.js +71 -29
- package/lib/types.d.ts +52 -62
- package/lib/versions.d.ts +3 -3
- package/lib/versions.js +76 -24
- package/package.json +22 -20
- package/src/__tests__/__fixtures__/simple-site/docs/_partials/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/simple-site/docs/_partials/subfolder/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/simple-site/docs/_somePartial.md +3 -0
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootAbsoluteSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootRelativeSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootResolvedSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/docs/rootTryToEscapeSlug.md +2 -0
- package/src/__tests__/__fixtures__/simple-site/sidebars.json +15 -1
- package/src/__tests__/__fixtures__/site-with-doc-label/docs/hello-1.md +1 -0
- package/src/__tests__/__fixtures__/versioned-site/docs/foo/bar.md +6 -0
- package/src/__tests__/__fixtures__/versioned-site/docs/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.0/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_partials/subfolder/somePartial.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/_somePartial.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_docs/version-1.0.1/hello.md +3 -0
- package/src/__tests__/__fixtures__/versioned-site/versioned_sidebars/version-1.0.1-sidebars.json +2 -2
- package/src/__tests__/__snapshots__/cli.test.ts.snap +48 -73
- package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
- package/src/__tests__/__snapshots__/index.test.ts.snap +753 -112
- package/src/__tests__/__snapshots__/translations.test.ts.snap +45 -18
- package/src/__tests__/cli.test.ts +15 -11
- package/src/__tests__/docFrontMatter.test.ts +195 -40
- package/src/__tests__/docs.test.ts +311 -150
- package/src/__tests__/index.test.ts +112 -69
- package/src/__tests__/lastUpdate.test.ts +3 -2
- package/src/__tests__/options.test.ts +48 -4
- package/src/__tests__/props.test.ts +62 -0
- package/src/__tests__/slug.test.ts +127 -20
- package/src/__tests__/translations.test.ts +7 -2
- package/src/__tests__/versions.test.ts +93 -67
- package/src/categoryGeneratedIndex.ts +57 -0
- package/src/cli.ts +8 -41
- package/src/client/__tests__/docsClientUtils.test.ts +4 -5
- package/src/client/docsClientUtils.ts +19 -41
- package/{types.d.ts → src/deps.d.ts} +0 -0
- package/src/docFrontMatter.ts +13 -7
- package/src/docs.ts +158 -29
- package/src/globalData.ts +6 -1
- package/src/index.ts +134 -179
- package/src/lastUpdate.ts +10 -9
- package/src/markdown/index.ts +8 -12
- package/src/numberPrefix.ts +5 -3
- package/src/options.ts +59 -28
- package/src/plugin-content-docs.d.ts +179 -35
- package/src/props.ts +91 -16
- package/src/routes.ts +173 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-shorthand.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-items.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category-wrong-label.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-category.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed-first-level.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-collapsed.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-doc-id-not-string.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-first-level-not-category.js +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-href.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link-wrong-label.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-link.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-unknown-type.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars-wrong-field.json +0 -0
- package/src/{__tests__ → sidebars/__tests__}/__fixtures__/sidebars/sidebars.json +0 -0
- package/src/{__tests__/__snapshots__/sidebars.test.ts.snap → sidebars/__tests__/__snapshots__/index.test.ts.snap} +36 -6
- package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +143 -18
- package/src/sidebars/__tests__/index.test.ts +204 -0
- package/src/sidebars/__tests__/processor.test.ts +237 -0
- package/src/sidebars/__tests__/utils.test.ts +695 -0
- package/src/sidebars/__tests__/validation.test.ts +105 -0
- package/src/sidebars/generator.ts +310 -0
- package/src/sidebars/index.ts +94 -0
- package/src/sidebars/normalization.ts +112 -0
- package/src/sidebars/processor.ts +154 -0
- package/src/sidebars/types.ts +211 -0
- package/src/sidebars/utils.ts +329 -0
- package/src/sidebars/validation.ts +168 -0
- package/src/slug.ts +32 -17
- package/src/tags.ts +19 -0
- package/src/theme/hooks/useDocs.ts +5 -1
- package/src/translations.ts +103 -47
- package/src/types.ts +67 -105
- package/src/versions.ts +117 -21
- package/lib/sidebarItemsGenerator.js +0 -211
- package/lib/sidebars.d.ts +0 -43
- package/lib/sidebars.js +0 -319
- package/src/__tests__/sidebars.test.ts +0 -639
- package/src/sidebarItemsGenerator.ts +0 -307
- 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';
|
|
@@ -16,25 +14,23 @@ import fs from 'fs-extra';
|
|
|
16
14
|
import pluginContentDocs from '../index';
|
|
17
15
|
import {loadContext} from '@docusaurus/core/src/server/index';
|
|
18
16
|
import {applyConfigureWebpack} from '@docusaurus/core/src/webpack/utils';
|
|
19
|
-
import {RouteConfig} from '@docusaurus/types';
|
|
20
|
-
import {posixPath} from '@docusaurus/utils';
|
|
17
|
+
import type {RouteConfig} from '@docusaurus/types';
|
|
18
|
+
import {posixPath, DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
|
|
21
19
|
import {sortConfig} from '@docusaurus/core/src/server/plugins';
|
|
22
|
-
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
|
|
23
20
|
|
|
24
21
|
import * as cliDocs from '../cli';
|
|
25
22
|
import {OptionsSchema} from '../options';
|
|
26
23
|
import {normalizePluginOptions} from '@docusaurus/utils-validation';
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
LoadedVersion,
|
|
24
|
+
import type {DocMetadata, LoadedVersion} from '../types';
|
|
25
|
+
import type {
|
|
30
26
|
SidebarItem,
|
|
31
27
|
SidebarItemsGeneratorOption,
|
|
32
28
|
SidebarItemsGeneratorOptionArgs,
|
|
33
|
-
} from '../types';
|
|
29
|
+
} from '../sidebars/types';
|
|
34
30
|
import {toSidebarsProp} from '../props';
|
|
35
31
|
|
|
36
32
|
import {validate} from 'webpack';
|
|
37
|
-
import {DefaultSidebarItemsGenerator} from '../
|
|
33
|
+
import {DefaultSidebarItemsGenerator} from '../sidebars/generator';
|
|
38
34
|
import {DisabledSidebars} from '../sidebars';
|
|
39
35
|
|
|
40
36
|
function findDocById(version: LoadedVersion, unversionedId: string) {
|
|
@@ -60,6 +56,7 @@ const defaultDocMetadata: Partial<DocMetadata> = {
|
|
|
60
56
|
lastUpdatedAt: undefined,
|
|
61
57
|
lastUpdatedBy: undefined,
|
|
62
58
|
formattedLastUpdatedAt: undefined,
|
|
59
|
+
tags: [],
|
|
63
60
|
};
|
|
64
61
|
|
|
65
62
|
const createFakeActions = (contentDir: string) => {
|
|
@@ -105,9 +102,6 @@ Entries created:
|
|
|
105
102
|
`version-${kebabCase(version.versionName)}-metadata-prop`,
|
|
106
103
|
);
|
|
107
104
|
expect(versionMetadataProp.docsSidebars).toEqual(toSidebarsProp(version));
|
|
108
|
-
expect(versionMetadataProp.permalinkToSidebar).toEqual(
|
|
109
|
-
version.permalinkToSidebar,
|
|
110
|
-
);
|
|
111
105
|
},
|
|
112
106
|
|
|
113
107
|
expectSnapshot: () => {
|
|
@@ -252,7 +246,6 @@ describe('simple website', () => {
|
|
|
252
246
|
normalizePluginOptions(OptionsSchema, {
|
|
253
247
|
path: 'docs',
|
|
254
248
|
sidebarPath,
|
|
255
|
-
homePageId: 'hello',
|
|
256
249
|
}),
|
|
257
250
|
);
|
|
258
251
|
const pluginContentDir = path.join(context.generatedFilesDir, plugin.name);
|
|
@@ -273,6 +266,8 @@ describe('simple website', () => {
|
|
|
273
266
|
expect(mock).toHaveBeenCalledWith('1.0.0', siteDir, DEFAULT_PLUGIN_ID, {
|
|
274
267
|
path: 'docs',
|
|
275
268
|
sidebarPath,
|
|
269
|
+
sidebarCollapsed: true,
|
|
270
|
+
sidebarCollapsible: true,
|
|
276
271
|
});
|
|
277
272
|
mock.mockRestore();
|
|
278
273
|
});
|
|
@@ -309,6 +304,8 @@ describe('simple website', () => {
|
|
|
309
304
|
test('configureWebpack', async () => {
|
|
310
305
|
const {plugin} = await loadSite();
|
|
311
306
|
|
|
307
|
+
const content = await plugin.loadContent?.();
|
|
308
|
+
|
|
312
309
|
const config = applyConfigureWebpack(
|
|
313
310
|
plugin.configureWebpack,
|
|
314
311
|
{
|
|
@@ -319,6 +316,8 @@ describe('simple website', () => {
|
|
|
319
316
|
},
|
|
320
317
|
},
|
|
321
318
|
false,
|
|
319
|
+
undefined,
|
|
320
|
+
content,
|
|
322
321
|
);
|
|
323
322
|
const errors = validate(config);
|
|
324
323
|
expect(errors).toBeUndefined();
|
|
@@ -336,7 +335,6 @@ describe('simple website', () => {
|
|
|
336
335
|
id: 'foo/baz',
|
|
337
336
|
unversionedId: 'foo/baz',
|
|
338
337
|
sourceDirName: 'foo',
|
|
339
|
-
isDocsHomePage: false,
|
|
340
338
|
permalink: '/docs/foo/bazSlug.html',
|
|
341
339
|
slug: '/foo/bazSlug.html',
|
|
342
340
|
previous: {
|
|
@@ -344,10 +342,11 @@ describe('simple website', () => {
|
|
|
344
342
|
permalink: '/docs/foo/bar',
|
|
345
343
|
},
|
|
346
344
|
next: {
|
|
347
|
-
title: '
|
|
348
|
-
permalink: '/docs/',
|
|
345
|
+
title: 'rootAbsoluteSlug',
|
|
346
|
+
permalink: '/docs/rootAbsoluteSlug',
|
|
349
347
|
},
|
|
350
348
|
sidebar: 'docs',
|
|
349
|
+
sidebarPosition: undefined,
|
|
351
350
|
source: path.posix.join(
|
|
352
351
|
'@site',
|
|
353
352
|
posixPath(path.relative(siteDir, currentVersion.contentPath)),
|
|
@@ -361,7 +360,23 @@ describe('simple website', () => {
|
|
|
361
360
|
title: 'baz',
|
|
362
361
|
slug: 'bazSlug.html',
|
|
363
362
|
pagination_label: 'baz pagination_label',
|
|
363
|
+
tags: [
|
|
364
|
+
'tag 1',
|
|
365
|
+
'tag-1', // This one will be de-duplicated as it would lead to the same permalink as the first
|
|
366
|
+
{label: 'tag 2', permalink: 'tag2-custom-permalink'},
|
|
367
|
+
],
|
|
364
368
|
},
|
|
369
|
+
|
|
370
|
+
tags: [
|
|
371
|
+
{
|
|
372
|
+
label: 'tag 1',
|
|
373
|
+
permalink: '/docs/tags/tag-1',
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
label: 'tag 2',
|
|
377
|
+
permalink: '/docs/tags/tag2-custom-permalink',
|
|
378
|
+
},
|
|
379
|
+
],
|
|
365
380
|
});
|
|
366
381
|
|
|
367
382
|
expect(findDocById(currentVersion, 'hello')).toEqual({
|
|
@@ -370,12 +385,11 @@ describe('simple website', () => {
|
|
|
370
385
|
id: 'hello',
|
|
371
386
|
unversionedId: 'hello',
|
|
372
387
|
sourceDirName: '.',
|
|
373
|
-
isDocsHomePage: true,
|
|
374
388
|
permalink: '/docs/',
|
|
375
389
|
slug: '/',
|
|
376
390
|
previous: {
|
|
377
|
-
title: '
|
|
378
|
-
permalink: '/docs/
|
|
391
|
+
title: 'My heading as title',
|
|
392
|
+
permalink: '/docs/headingAsTitle',
|
|
379
393
|
},
|
|
380
394
|
sidebar: 'docs',
|
|
381
395
|
source: path.posix.join(
|
|
@@ -389,7 +403,19 @@ describe('simple website', () => {
|
|
|
389
403
|
id: 'hello',
|
|
390
404
|
title: 'Hello, World !',
|
|
391
405
|
sidebar_label: 'Hello sidebar_label',
|
|
406
|
+
slug: '/',
|
|
407
|
+
tags: ['tag-1', 'tag 3'],
|
|
392
408
|
},
|
|
409
|
+
tags: [
|
|
410
|
+
{
|
|
411
|
+
label: 'tag-1',
|
|
412
|
+
permalink: '/docs/tags/tag-1',
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
label: 'tag 3',
|
|
416
|
+
permalink: '/docs/tags/tag-3',
|
|
417
|
+
},
|
|
418
|
+
],
|
|
393
419
|
});
|
|
394
420
|
|
|
395
421
|
expect(getDocById(currentVersion, 'foo/bar')).toEqual({
|
|
@@ -398,7 +424,6 @@ describe('simple website', () => {
|
|
|
398
424
|
id: 'foo/bar',
|
|
399
425
|
unversionedId: 'foo/bar',
|
|
400
426
|
sourceDirName: 'foo',
|
|
401
|
-
isDocsHomePage: false,
|
|
402
427
|
next: {
|
|
403
428
|
title: 'baz pagination_label',
|
|
404
429
|
permalink: '/docs/foo/bazSlug.html',
|
|
@@ -450,7 +475,6 @@ describe('versioned website', () => {
|
|
|
450
475
|
normalizePluginOptions(OptionsSchema, {
|
|
451
476
|
routeBasePath,
|
|
452
477
|
sidebarPath,
|
|
453
|
-
homePageId: 'hello',
|
|
454
478
|
}),
|
|
455
479
|
);
|
|
456
480
|
const pluginContentDir = path.join(context.generatedFilesDir, plugin.name);
|
|
@@ -477,6 +501,8 @@ describe('versioned website', () => {
|
|
|
477
501
|
expect(mock).toHaveBeenCalledWith('2.0.0', siteDir, DEFAULT_PLUGIN_ID, {
|
|
478
502
|
path: routeBasePath,
|
|
479
503
|
sidebarPath,
|
|
504
|
+
sidebarCollapsed: true,
|
|
505
|
+
sidebarCollapsible: true,
|
|
480
506
|
});
|
|
481
507
|
mock.mockRestore();
|
|
482
508
|
});
|
|
@@ -544,12 +570,8 @@ describe('versioned website', () => {
|
|
|
544
570
|
const {siteDir, plugin, pluginContentDir} = await loadSite();
|
|
545
571
|
const content = await plugin.loadContent!();
|
|
546
572
|
expect(content.loadedVersions.length).toEqual(4);
|
|
547
|
-
const [
|
|
548
|
-
|
|
549
|
-
version101,
|
|
550
|
-
version100,
|
|
551
|
-
versionWithSlugs,
|
|
552
|
-
] = content.loadedVersions;
|
|
573
|
+
const [currentVersion, version101, version100, versionWithSlugs] =
|
|
574
|
+
content.loadedVersions;
|
|
553
575
|
|
|
554
576
|
// foo/baz.md only exists in version -1.0.0
|
|
555
577
|
expect(findDocById(currentVersion, 'foo/baz')).toBeUndefined();
|
|
@@ -561,7 +583,6 @@ describe('versioned website', () => {
|
|
|
561
583
|
id: 'foo/bar',
|
|
562
584
|
unversionedId: 'foo/bar',
|
|
563
585
|
sourceDirName: 'foo',
|
|
564
|
-
isDocsHomePage: false,
|
|
565
586
|
permalink: '/docs/next/foo/barSlug',
|
|
566
587
|
slug: '/foo/barSlug',
|
|
567
588
|
source: path.posix.join(
|
|
@@ -574,6 +595,11 @@ describe('versioned website', () => {
|
|
|
574
595
|
description: 'This is next version of bar.',
|
|
575
596
|
frontMatter: {
|
|
576
597
|
slug: 'barSlug',
|
|
598
|
+
tags: [
|
|
599
|
+
'barTag 1',
|
|
600
|
+
'barTag-2',
|
|
601
|
+
{label: 'barTag 3', permalink: 'barTag-3-permalink'},
|
|
602
|
+
],
|
|
577
603
|
},
|
|
578
604
|
version: 'current',
|
|
579
605
|
sidebar: 'docs',
|
|
@@ -581,13 +607,42 @@ describe('versioned website', () => {
|
|
|
581
607
|
title: 'hello',
|
|
582
608
|
permalink: '/docs/next/',
|
|
583
609
|
},
|
|
610
|
+
tags: [
|
|
611
|
+
{label: 'barTag 1', permalink: '/docs/next/tags/bar-tag-1'},
|
|
612
|
+
{label: 'barTag-2', permalink: '/docs/next/tags/bar-tag-2'},
|
|
613
|
+
{label: 'barTag 3', permalink: '/docs/next/tags/barTag-3-permalink'},
|
|
614
|
+
],
|
|
615
|
+
});
|
|
616
|
+
expect(getDocById(version101, 'foo/bar')).toEqual({
|
|
617
|
+
...defaultDocMetadata,
|
|
618
|
+
id: 'version-1.0.1/foo/bar',
|
|
619
|
+
unversionedId: 'foo/bar',
|
|
620
|
+
sourceDirName: 'foo',
|
|
621
|
+
permalink: '/docs/foo/bar',
|
|
622
|
+
slug: '/foo/bar',
|
|
623
|
+
source: path.posix.join(
|
|
624
|
+
'@site',
|
|
625
|
+
posixPath(path.relative(siteDir, version101.contentPath)),
|
|
626
|
+
'foo',
|
|
627
|
+
'bar.md',
|
|
628
|
+
),
|
|
629
|
+
title: 'bar',
|
|
630
|
+
description: 'Bar 1.0.1 !',
|
|
631
|
+
frontMatter: {},
|
|
632
|
+
version: '1.0.1',
|
|
633
|
+
sidebar: 'VersionedSideBarNameDoesNotMatter/docs',
|
|
634
|
+
next: {
|
|
635
|
+
title: 'hello',
|
|
636
|
+
permalink: '/docs/',
|
|
637
|
+
},
|
|
638
|
+
tags: [],
|
|
584
639
|
});
|
|
640
|
+
|
|
585
641
|
expect(getDocById(currentVersion, 'hello')).toEqual({
|
|
586
642
|
...defaultDocMetadata,
|
|
587
643
|
id: 'hello',
|
|
588
644
|
unversionedId: 'hello',
|
|
589
645
|
sourceDirName: '.',
|
|
590
|
-
isDocsHomePage: true,
|
|
591
646
|
permalink: '/docs/next/',
|
|
592
647
|
slug: '/',
|
|
593
648
|
source: path.posix.join(
|
|
@@ -597,7 +652,9 @@ describe('versioned website', () => {
|
|
|
597
652
|
),
|
|
598
653
|
title: 'hello',
|
|
599
654
|
description: 'Hello next !',
|
|
600
|
-
frontMatter: {
|
|
655
|
+
frontMatter: {
|
|
656
|
+
slug: '/',
|
|
657
|
+
},
|
|
601
658
|
version: 'current',
|
|
602
659
|
sidebar: 'docs',
|
|
603
660
|
previous: {
|
|
@@ -610,7 +667,6 @@ describe('versioned website', () => {
|
|
|
610
667
|
id: 'version-1.0.1/hello',
|
|
611
668
|
unversionedId: 'hello',
|
|
612
669
|
sourceDirName: '.',
|
|
613
|
-
isDocsHomePage: true,
|
|
614
670
|
permalink: '/docs/',
|
|
615
671
|
slug: '/',
|
|
616
672
|
source: path.posix.join(
|
|
@@ -620,9 +676,11 @@ describe('versioned website', () => {
|
|
|
620
676
|
),
|
|
621
677
|
title: 'hello',
|
|
622
678
|
description: 'Hello 1.0.1 !',
|
|
623
|
-
frontMatter: {
|
|
679
|
+
frontMatter: {
|
|
680
|
+
slug: '/',
|
|
681
|
+
},
|
|
624
682
|
version: '1.0.1',
|
|
625
|
-
sidebar: '
|
|
683
|
+
sidebar: 'VersionedSideBarNameDoesNotMatter/docs',
|
|
626
684
|
previous: {
|
|
627
685
|
title: 'bar',
|
|
628
686
|
permalink: '/docs/foo/bar',
|
|
@@ -633,7 +691,6 @@ describe('versioned website', () => {
|
|
|
633
691
|
id: 'version-1.0.0/foo/baz',
|
|
634
692
|
unversionedId: 'foo/baz',
|
|
635
693
|
sourceDirName: 'foo',
|
|
636
|
-
isDocsHomePage: false,
|
|
637
694
|
permalink: '/docs/1.0.0/foo/baz',
|
|
638
695
|
slug: '/foo/baz',
|
|
639
696
|
source: path.posix.join(
|
|
@@ -710,13 +767,8 @@ describe('versioned website (community)', () => {
|
|
|
710
767
|
}
|
|
711
768
|
|
|
712
769
|
test('extendCli - docsVersion', async () => {
|
|
713
|
-
const {
|
|
714
|
-
|
|
715
|
-
routeBasePath,
|
|
716
|
-
sidebarPath,
|
|
717
|
-
pluginId,
|
|
718
|
-
plugin,
|
|
719
|
-
} = await loadSite();
|
|
770
|
+
const {siteDir, routeBasePath, sidebarPath, pluginId, plugin} =
|
|
771
|
+
await loadSite();
|
|
720
772
|
const mock = jest
|
|
721
773
|
.spyOn(cliDocs, 'cliDocsVersionCommand')
|
|
722
774
|
.mockImplementation();
|
|
@@ -728,6 +780,8 @@ describe('versioned website (community)', () => {
|
|
|
728
780
|
expect(mock).toHaveBeenCalledWith('2.0.0', siteDir, pluginId, {
|
|
729
781
|
path: routeBasePath,
|
|
730
782
|
sidebarPath,
|
|
783
|
+
sidebarCollapsed: true,
|
|
784
|
+
sidebarCollapsible: true,
|
|
731
785
|
});
|
|
732
786
|
mock.mockRestore();
|
|
733
787
|
});
|
|
@@ -784,7 +838,6 @@ describe('versioned website (community)', () => {
|
|
|
784
838
|
id: 'team',
|
|
785
839
|
unversionedId: 'team',
|
|
786
840
|
sourceDirName: '.',
|
|
787
|
-
isDocsHomePage: false,
|
|
788
841
|
permalink: '/community/next/team',
|
|
789
842
|
slug: '/team',
|
|
790
843
|
source:
|
|
@@ -800,7 +853,6 @@ describe('versioned website (community)', () => {
|
|
|
800
853
|
id: 'version-1.0.0/team',
|
|
801
854
|
unversionedId: 'team',
|
|
802
855
|
sourceDirName: '.',
|
|
803
|
-
isDocsHomePage: false,
|
|
804
856
|
permalink: '/community/team',
|
|
805
857
|
slug: '/team',
|
|
806
858
|
source: path.posix.join(
|
|
@@ -842,7 +894,6 @@ describe('site with doc label', () => {
|
|
|
842
894
|
normalizePluginOptions(OptionsSchema, {
|
|
843
895
|
path: 'docs',
|
|
844
896
|
sidebarPath,
|
|
845
|
-
homePageId: 'hello-1',
|
|
846
897
|
}),
|
|
847
898
|
);
|
|
848
899
|
|
|
@@ -906,6 +957,7 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
906
957
|
type: 'category',
|
|
907
958
|
label: 'Guides',
|
|
908
959
|
collapsed: true,
|
|
960
|
+
collapsible: true,
|
|
909
961
|
items: [
|
|
910
962
|
{
|
|
911
963
|
type: 'doc',
|
|
@@ -937,6 +989,7 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
937
989
|
type: 'category',
|
|
938
990
|
label: 'API (label from _category_.json)',
|
|
939
991
|
collapsed: true,
|
|
992
|
+
collapsible: true,
|
|
940
993
|
items: [
|
|
941
994
|
{
|
|
942
995
|
type: 'doc',
|
|
@@ -946,6 +999,7 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
946
999
|
type: 'category',
|
|
947
1000
|
label: 'Core APIs',
|
|
948
1001
|
collapsed: true,
|
|
1002
|
+
collapsible: true,
|
|
949
1003
|
items: [
|
|
950
1004
|
{
|
|
951
1005
|
type: 'doc',
|
|
@@ -962,6 +1016,7 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
962
1016
|
type: 'category',
|
|
963
1017
|
label: 'Extension APIs (label from _category_.yml)',
|
|
964
1018
|
collapsed: true,
|
|
1019
|
+
collapsible: true,
|
|
965
1020
|
items: [
|
|
966
1021
|
{
|
|
967
1022
|
type: 'doc',
|
|
@@ -983,7 +1038,7 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
983
1038
|
});
|
|
984
1039
|
});
|
|
985
1040
|
|
|
986
|
-
test('docs in fully generated sidebar have correct
|
|
1041
|
+
test('docs in fully generated sidebar have correct metadata', async () => {
|
|
987
1042
|
const {content, siteDir} = await loadSite();
|
|
988
1043
|
const version = content.loadedVersions[0];
|
|
989
1044
|
|
|
@@ -992,7 +1047,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
992
1047
|
id: 'getting-started',
|
|
993
1048
|
unversionedId: 'getting-started',
|
|
994
1049
|
sourceDirName: '.',
|
|
995
|
-
isDocsHomePage: false,
|
|
996
1050
|
permalink: '/docs/getting-started',
|
|
997
1051
|
slug: '/getting-started',
|
|
998
1052
|
source: path.posix.join(
|
|
@@ -1018,7 +1072,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1018
1072
|
id: 'installation',
|
|
1019
1073
|
unversionedId: 'installation',
|
|
1020
1074
|
sourceDirName: '.',
|
|
1021
|
-
isDocsHomePage: false,
|
|
1022
1075
|
permalink: '/docs/installation',
|
|
1023
1076
|
slug: '/installation',
|
|
1024
1077
|
source: path.posix.join(
|
|
@@ -1047,7 +1100,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1047
1100
|
id: 'Guides/guide1',
|
|
1048
1101
|
unversionedId: 'Guides/guide1',
|
|
1049
1102
|
sourceDirName: 'Guides',
|
|
1050
|
-
isDocsHomePage: false,
|
|
1051
1103
|
permalink: '/docs/Guides/guide1',
|
|
1052
1104
|
slug: '/Guides/guide1',
|
|
1053
1105
|
source: path.posix.join(
|
|
@@ -1080,7 +1132,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1080
1132
|
id: 'Guides/guide2',
|
|
1081
1133
|
unversionedId: 'Guides/guide2',
|
|
1082
1134
|
sourceDirName: 'Guides',
|
|
1083
|
-
isDocsHomePage: false,
|
|
1084
1135
|
permalink: '/docs/Guides/guide2',
|
|
1085
1136
|
slug: '/Guides/guide2',
|
|
1086
1137
|
source: path.posix.join(
|
|
@@ -1112,7 +1163,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1112
1163
|
id: 'Guides/guide2.5',
|
|
1113
1164
|
unversionedId: 'Guides/guide2.5',
|
|
1114
1165
|
sourceDirName: 'Guides',
|
|
1115
|
-
isDocsHomePage: false,
|
|
1116
1166
|
permalink: '/docs/Guides/guide2.5',
|
|
1117
1167
|
slug: '/Guides/guide2.5',
|
|
1118
1168
|
source: path.posix.join(
|
|
@@ -1145,7 +1195,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1145
1195
|
id: 'Guides/guide3',
|
|
1146
1196
|
unversionedId: 'Guides/guide3',
|
|
1147
1197
|
sourceDirName: 'Guides',
|
|
1148
|
-
isDocsHomePage: false,
|
|
1149
1198
|
permalink: '/docs/Guides/guide3',
|
|
1150
1199
|
slug: '/Guides/guide3',
|
|
1151
1200
|
source: path.posix.join(
|
|
@@ -1178,7 +1227,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1178
1227
|
id: 'Guides/guide4',
|
|
1179
1228
|
unversionedId: 'Guides/guide4',
|
|
1180
1229
|
sourceDirName: 'Guides',
|
|
1181
|
-
isDocsHomePage: false,
|
|
1182
1230
|
permalink: '/docs/Guides/guide4',
|
|
1183
1231
|
slug: '/Guides/guide4',
|
|
1184
1232
|
source: path.posix.join(
|
|
@@ -1210,7 +1258,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1210
1258
|
id: 'Guides/guide5',
|
|
1211
1259
|
unversionedId: 'Guides/guide5',
|
|
1212
1260
|
sourceDirName: 'Guides',
|
|
1213
|
-
isDocsHomePage: false,
|
|
1214
1261
|
permalink: '/docs/Guides/guide5',
|
|
1215
1262
|
slug: '/Guides/guide5',
|
|
1216
1263
|
source: path.posix.join(
|
|
@@ -1242,7 +1289,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1242
1289
|
id: 'API/api-overview',
|
|
1243
1290
|
unversionedId: 'API/api-overview',
|
|
1244
1291
|
sourceDirName: '3-API',
|
|
1245
|
-
isDocsHomePage: false,
|
|
1246
1292
|
permalink: '/docs/API/api-overview',
|
|
1247
1293
|
slug: '/API/api-overview',
|
|
1248
1294
|
source: path.posix.join(
|
|
@@ -1272,7 +1318,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1272
1318
|
id: 'API/Core APIs/Client API',
|
|
1273
1319
|
unversionedId: 'API/Core APIs/Client API',
|
|
1274
1320
|
sourceDirName: '3-API/01_Core APIs',
|
|
1275
|
-
isDocsHomePage: false,
|
|
1276
1321
|
permalink: '/docs/API/Core APIs/Client API',
|
|
1277
1322
|
slug: '/API/Core APIs/Client API',
|
|
1278
1323
|
source: path.posix.join(
|
|
@@ -1303,7 +1348,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1303
1348
|
id: 'API/Core APIs/Server API',
|
|
1304
1349
|
unversionedId: 'API/Core APIs/Server API',
|
|
1305
1350
|
sourceDirName: '3-API/01_Core APIs',
|
|
1306
|
-
isDocsHomePage: false,
|
|
1307
1351
|
permalink: '/docs/API/Core APIs/Server API',
|
|
1308
1352
|
slug: '/API/Core APIs/Server API',
|
|
1309
1353
|
source: path.posix.join(
|
|
@@ -1334,7 +1378,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1334
1378
|
id: 'API/Extension APIs/Plugin API',
|
|
1335
1379
|
unversionedId: 'API/Extension APIs/Plugin API',
|
|
1336
1380
|
sourceDirName: '3-API/02_Extension APIs',
|
|
1337
|
-
isDocsHomePage: false,
|
|
1338
1381
|
permalink: '/docs/API/Extension APIs/Plugin API',
|
|
1339
1382
|
slug: '/API/Extension APIs/Plugin API',
|
|
1340
1383
|
source: path.posix.join(
|
|
@@ -1365,7 +1408,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1365
1408
|
id: 'API/Extension APIs/Theme API',
|
|
1366
1409
|
unversionedId: 'API/Extension APIs/Theme API',
|
|
1367
1410
|
sourceDirName: '3-API/02_Extension APIs',
|
|
1368
|
-
isDocsHomePage: false,
|
|
1369
1411
|
permalink: '/docs/API/Extension APIs/Theme API',
|
|
1370
1412
|
slug: '/API/Extension APIs/Theme API',
|
|
1371
1413
|
source: path.posix.join(
|
|
@@ -1396,7 +1438,6 @@ describe('site with full autogenerated sidebar', () => {
|
|
|
1396
1438
|
id: 'API/api-end',
|
|
1397
1439
|
unversionedId: 'API/api-end',
|
|
1398
1440
|
sourceDirName: '3-API',
|
|
1399
|
-
isDocsHomePage: false,
|
|
1400
1441
|
permalink: '/docs/API/api-end',
|
|
1401
1442
|
slug: '/API/api-end',
|
|
1402
1443
|
source: path.posix.join(
|
|
@@ -1460,6 +1501,7 @@ describe('site with partial autogenerated sidebars', () => {
|
|
|
1460
1501
|
type: 'category',
|
|
1461
1502
|
label: 'Some category',
|
|
1462
1503
|
collapsed: true,
|
|
1504
|
+
collapsible: true,
|
|
1463
1505
|
items: [
|
|
1464
1506
|
{
|
|
1465
1507
|
type: 'doc',
|
|
@@ -1479,18 +1521,17 @@ describe('site with partial autogenerated sidebars', () => {
|
|
|
1479
1521
|
});
|
|
1480
1522
|
});
|
|
1481
1523
|
|
|
1482
|
-
test('docs in partially generated sidebar have correct
|
|
1524
|
+
test('docs in partially generated sidebar have correct metadata', async () => {
|
|
1483
1525
|
const {content, siteDir} = await loadSite();
|
|
1484
1526
|
const version = content.loadedVersions[0];
|
|
1485
1527
|
|
|
1486
|
-
// Only looking at the docs of the autogen sidebar, others
|
|
1528
|
+
// Only looking at the docs of the autogen sidebar, others metadata should not be affected
|
|
1487
1529
|
|
|
1488
1530
|
expect(getDocById(version, 'API/api-end')).toEqual({
|
|
1489
1531
|
...defaultDocMetadata,
|
|
1490
1532
|
id: 'API/api-end',
|
|
1491
1533
|
unversionedId: 'API/api-end',
|
|
1492
1534
|
sourceDirName: '3-API',
|
|
1493
|
-
isDocsHomePage: false,
|
|
1494
1535
|
permalink: '/docs/API/api-end',
|
|
1495
1536
|
slug: '/API/api-end',
|
|
1496
1537
|
source: path.posix.join(
|
|
@@ -1517,7 +1558,6 @@ describe('site with partial autogenerated sidebars', () => {
|
|
|
1517
1558
|
id: 'API/api-overview',
|
|
1518
1559
|
unversionedId: 'API/api-overview',
|
|
1519
1560
|
sourceDirName: '3-API',
|
|
1520
|
-
isDocsHomePage: false,
|
|
1521
1561
|
permalink: '/docs/API/api-overview',
|
|
1522
1562
|
slug: '/API/api-overview',
|
|
1523
1563
|
source: path.posix.join(
|
|
@@ -1547,7 +1587,6 @@ describe('site with partial autogenerated sidebars', () => {
|
|
|
1547
1587
|
id: 'API/Extension APIs/Plugin API',
|
|
1548
1588
|
unversionedId: 'API/Extension APIs/Plugin API',
|
|
1549
1589
|
sourceDirName: '3-API/02_Extension APIs',
|
|
1550
|
-
isDocsHomePage: false,
|
|
1551
1590
|
permalink: '/docs/API/Extension APIs/Plugin API',
|
|
1552
1591
|
slug: '/API/Extension APIs/Plugin API',
|
|
1553
1592
|
source: path.posix.join(
|
|
@@ -1578,7 +1617,6 @@ describe('site with partial autogenerated sidebars', () => {
|
|
|
1578
1617
|
id: 'API/Extension APIs/Theme API',
|
|
1579
1618
|
unversionedId: 'API/Extension APIs/Theme API',
|
|
1580
1619
|
sourceDirName: '3-API/02_Extension APIs',
|
|
1581
|
-
isDocsHomePage: false,
|
|
1582
1620
|
permalink: '/docs/API/Extension APIs/Theme API',
|
|
1583
1621
|
slug: '/API/Extension APIs/Theme API',
|
|
1584
1622
|
source: path.posix.join(
|
|
@@ -1649,6 +1687,7 @@ describe('site with partial autogenerated sidebars 2 (fix #4638)', () => {
|
|
|
1649
1687
|
type: 'category',
|
|
1650
1688
|
label: 'Core APIs',
|
|
1651
1689
|
collapsed: true,
|
|
1690
|
+
collapsible: true,
|
|
1652
1691
|
items: [
|
|
1653
1692
|
{
|
|
1654
1693
|
type: 'doc',
|
|
@@ -1665,6 +1704,7 @@ describe('site with partial autogenerated sidebars 2 (fix #4638)', () => {
|
|
|
1665
1704
|
type: 'category',
|
|
1666
1705
|
label: 'Extension APIs (label from _category_.yml)', // Fix #4638
|
|
1667
1706
|
collapsed: true,
|
|
1707
|
+
collapsible: true,
|
|
1668
1708
|
items: [
|
|
1669
1709
|
{
|
|
1670
1710
|
type: 'doc',
|
|
@@ -1734,12 +1774,11 @@ describe('site with custom sidebar items generator', () => {
|
|
|
1734
1774
|
});
|
|
1735
1775
|
|
|
1736
1776
|
test('sidebar is autogenerated according to a custom sidebarItemsGenerator', async () => {
|
|
1737
|
-
const customSidebarItemsGenerator: SidebarItemsGeneratorOption =
|
|
1738
|
-
|
|
1777
|
+
const customSidebarItemsGenerator: SidebarItemsGeneratorOption =
|
|
1778
|
+
async () => [
|
|
1739
1779
|
{type: 'doc', id: 'API/api-overview'},
|
|
1740
1780
|
{type: 'doc', id: 'API/api-end'},
|
|
1741
1781
|
];
|
|
1742
|
-
};
|
|
1743
1782
|
|
|
1744
1783
|
const {content} = await loadSite(customSidebarItemsGenerator);
|
|
1745
1784
|
const version = content.loadedVersions[0];
|
|
@@ -1781,6 +1820,7 @@ describe('site with custom sidebar items generator', () => {
|
|
|
1781
1820
|
type: 'category',
|
|
1782
1821
|
label: 'API (label from _category_.json)',
|
|
1783
1822
|
collapsed: true,
|
|
1823
|
+
collapsible: true,
|
|
1784
1824
|
items: [
|
|
1785
1825
|
{
|
|
1786
1826
|
type: 'doc',
|
|
@@ -1790,6 +1830,7 @@ describe('site with custom sidebar items generator', () => {
|
|
|
1790
1830
|
type: 'category',
|
|
1791
1831
|
label: 'Extension APIs (label from _category_.yml)',
|
|
1792
1832
|
collapsed: true,
|
|
1833
|
+
collapsible: true,
|
|
1793
1834
|
items: [
|
|
1794
1835
|
{
|
|
1795
1836
|
type: 'doc',
|
|
@@ -1805,6 +1846,7 @@ describe('site with custom sidebar items generator', () => {
|
|
|
1805
1846
|
type: 'category',
|
|
1806
1847
|
label: 'Core APIs',
|
|
1807
1848
|
collapsed: true,
|
|
1849
|
+
collapsible: true,
|
|
1808
1850
|
items: [
|
|
1809
1851
|
{
|
|
1810
1852
|
type: 'doc',
|
|
@@ -1826,6 +1868,7 @@ describe('site with custom sidebar items generator', () => {
|
|
|
1826
1868
|
type: 'category',
|
|
1827
1869
|
label: 'Guides',
|
|
1828
1870
|
collapsed: true,
|
|
1871
|
+
collapsible: true,
|
|
1829
1872
|
items: [
|
|
1830
1873
|
{
|
|
1831
1874
|
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
|
-
|
|
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
|
-
|
|
43
|
+
' with exit code 128',
|
|
43
44
|
);
|
|
44
45
|
expect(await getFileLastUpdate(null)).toBeNull();
|
|
45
46
|
expect(await getFileLastUpdate(undefined)).toBeNull();
|