@docusaurus/plugin-content-docs 2.0.0-beta.8e9b829d9 → 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.
- package/lib/.tsbuildinfo +1 -1
- package/lib/cli.d.ts +1 -1
- package/lib/cli.js +18 -23
- package/lib/client/docsClientUtils.d.ts +0 -3
- package/lib/client/docsClientUtils.js +10 -7
- package/lib/docFrontMatter.js +6 -2
- package/lib/docs.d.ts +3 -1
- package/lib/docs.js +76 -25
- package/lib/index.js +70 -77
- package/lib/lastUpdate.js +4 -4
- package/lib/markdown/index.d.ts +3 -6
- package/lib/markdown/index.js +3 -3
- package/lib/markdown/linkify.js +2 -2
- package/lib/options.js +12 -4
- package/lib/props.d.ts +7 -2
- package/lib/props.js +26 -3
- package/lib/{sidebarItemsGenerator.d.ts → sidebars/generator.d.ts} +2 -1
- package/lib/sidebars/generator.js +174 -0
- package/lib/sidebars/index.d.ts +14 -0
- package/lib/sidebars/index.js +64 -0
- package/lib/sidebars/normalization.d.ts +9 -0
- package/lib/sidebars/normalization.js +58 -0
- package/lib/sidebars/processor.d.ts +16 -0
- package/lib/sidebars/processor.js +70 -0
- package/lib/sidebars/types.d.ts +87 -0
- package/lib/sidebars/types.js +13 -0
- package/lib/sidebars/utils.d.ts +22 -0
- package/lib/sidebars/utils.js +101 -0
- package/lib/sidebars/validation.d.ts +8 -0
- package/lib/sidebars/validation.js +102 -0
- package/lib/slug.js +4 -4
- package/lib/tags.d.ts +8 -0
- package/lib/tags.js +22 -0
- package/lib/theme/hooks/useDocs.js +21 -21
- package/lib/translations.d.ts +1 -1
- package/lib/translations.js +13 -13
- package/lib/types.d.ts +29 -61
- package/lib/versions.d.ts +1 -1
- package/lib/versions.js +40 -20
- package/package.json +15 -14
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +5 -0
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +1 -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__/versioned-site/docs/foo/bar.md +6 -0
- package/src/__tests__/__snapshots__/cli.test.ts.snap +28 -0
- package/src/__tests__/__snapshots__/docs.test.ts.snap +140 -0
- package/src/__tests__/__snapshots__/index.test.ts.snap +426 -25
- package/src/__tests__/docFrontMatter.test.ts +160 -45
- package/src/__tests__/docs.test.ts +167 -21
- package/src/__tests__/index.test.ts +53 -27
- package/src/__tests__/options.test.ts +4 -1
- package/src/__tests__/props.test.ts +62 -0
- package/src/__tests__/versions.test.ts +68 -63
- package/src/cli.ts +23 -30
- package/src/client/docsClientUtils.ts +1 -12
- package/src/docFrontMatter.ts +7 -2
- package/src/docs.ts +88 -9
- package/src/index.ts +77 -91
- package/src/markdown/index.ts +8 -12
- package/src/numberPrefix.ts +4 -2
- package/src/options.ts +13 -1
- package/src/plugin-content-docs.d.ts +107 -32
- package/src/props.ts +41 -5
- 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} +6 -6
- package/src/{__tests__/sidebarItemsGenerator.test.ts → sidebars/__tests__/generator.test.ts} +2 -2
- package/src/sidebars/__tests__/index.test.ts +202 -0
- package/src/sidebars/__tests__/processor.test.ts +148 -0
- package/src/sidebars/__tests__/utils.test.ts +395 -0
- package/src/sidebars/generator.ts +253 -0
- package/src/sidebars/index.ts +84 -0
- package/src/sidebars/normalization.ts +88 -0
- package/src/sidebars/processor.ts +124 -0
- package/src/sidebars/types.ts +156 -0
- package/src/sidebars/utils.ts +146 -0
- package/src/sidebars/validation.ts +124 -0
- package/src/tags.ts +21 -0
- package/src/translations.ts +26 -36
- package/src/types.ts +35 -101
- package/src/versions.ts +51 -21
- package/lib/sidebarItemsGenerator.js +0 -215
- package/lib/sidebars.d.ts +0 -45
- package/lib/sidebars.js +0 -354
- package/src/__tests__/sidebars.test.ts +0 -746
- package/src/sidebarItemsGenerator.ts +0 -315
- package/src/sidebars.ts +0 -589
|
@@ -7,7 +7,13 @@
|
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import {loadContext} from '@docusaurus/core/src/server/index';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
processDocMetadata,
|
|
12
|
+
readVersionDocs,
|
|
13
|
+
readDocFile,
|
|
14
|
+
handleNavigation,
|
|
15
|
+
} from '../docs';
|
|
16
|
+
import {loadSidebars} from '../sidebars';
|
|
11
17
|
import {readVersionsMetadata} from '../versions';
|
|
12
18
|
import {
|
|
13
19
|
DocFile,
|
|
@@ -16,6 +22,7 @@ import {
|
|
|
16
22
|
VersionMetadata,
|
|
17
23
|
PluginOptions,
|
|
18
24
|
EditUrlFunction,
|
|
25
|
+
DocNavLink,
|
|
19
26
|
} from '../types';
|
|
20
27
|
import {LoadContext} from '@docusaurus/types';
|
|
21
28
|
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
|
|
@@ -110,7 +117,38 @@ function createTestUtils({
|
|
|
110
117
|
expect(metadata.permalink).toEqual(expectedPermalink);
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
|
|
120
|
+
async function generateNavigation(
|
|
121
|
+
docFiles: DocFile[],
|
|
122
|
+
): Promise<[DocNavLink, DocNavLink][]> {
|
|
123
|
+
const rawDocs = await Promise.all(
|
|
124
|
+
docFiles.map((docFile) =>
|
|
125
|
+
processDocMetadata({
|
|
126
|
+
docFile,
|
|
127
|
+
versionMetadata,
|
|
128
|
+
context,
|
|
129
|
+
options,
|
|
130
|
+
}),
|
|
131
|
+
),
|
|
132
|
+
);
|
|
133
|
+
const sidebars = await loadSidebars(versionMetadata.sidebarFilePath, {
|
|
134
|
+
sidebarItemsGenerator: ({defaultSidebarItemsGenerator, ...args}) =>
|
|
135
|
+
defaultSidebarItemsGenerator({...args}),
|
|
136
|
+
numberPrefixParser: options.numberPrefixParser,
|
|
137
|
+
docs: rawDocs,
|
|
138
|
+
version: versionMetadata,
|
|
139
|
+
options: {
|
|
140
|
+
sidebarCollapsed: false,
|
|
141
|
+
sidebarCollapsible: true,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
return handleNavigation(
|
|
145
|
+
rawDocs,
|
|
146
|
+
sidebars,
|
|
147
|
+
versionMetadata.sidebarFilePath as string,
|
|
148
|
+
).docs.map((doc) => [doc.previous, doc.next]);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {processDocFile, testMeta, testSlug, generateNavigation};
|
|
114
152
|
}
|
|
115
153
|
|
|
116
154
|
describe('simple site', () => {
|
|
@@ -187,6 +225,7 @@ describe('simple site', () => {
|
|
|
187
225
|
id: 'bar',
|
|
188
226
|
title: 'Bar',
|
|
189
227
|
},
|
|
228
|
+
tags: [],
|
|
190
229
|
});
|
|
191
230
|
await defaultTestUtils.testMeta(path.join('hello.md'), {
|
|
192
231
|
version: 'current',
|
|
@@ -202,7 +241,18 @@ describe('simple site', () => {
|
|
|
202
241
|
id: 'hello',
|
|
203
242
|
title: 'Hello, World !',
|
|
204
243
|
sidebar_label: 'Hello sidebar_label',
|
|
244
|
+
tags: ['tag-1', 'tag 3'],
|
|
205
245
|
},
|
|
246
|
+
tags: [
|
|
247
|
+
{
|
|
248
|
+
label: 'tag-1',
|
|
249
|
+
permalink: '/docs/tags/tag-1',
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
label: 'tag 3',
|
|
253
|
+
permalink: '/docs/tags/tag-3',
|
|
254
|
+
},
|
|
255
|
+
],
|
|
206
256
|
});
|
|
207
257
|
});
|
|
208
258
|
|
|
@@ -232,7 +282,18 @@ describe('simple site', () => {
|
|
|
232
282
|
id: 'hello',
|
|
233
283
|
title: 'Hello, World !',
|
|
234
284
|
sidebar_label: 'Hello sidebar_label',
|
|
285
|
+
tags: ['tag-1', 'tag 3'],
|
|
235
286
|
},
|
|
287
|
+
tags: [
|
|
288
|
+
{
|
|
289
|
+
label: 'tag-1',
|
|
290
|
+
permalink: '/docs/tags/tag-1',
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
label: 'tag 3',
|
|
294
|
+
permalink: '/docs/tags/tag-3',
|
|
295
|
+
},
|
|
296
|
+
],
|
|
236
297
|
});
|
|
237
298
|
});
|
|
238
299
|
|
|
@@ -263,13 +324,14 @@ describe('simple site', () => {
|
|
|
263
324
|
id: 'bar',
|
|
264
325
|
title: 'Bar',
|
|
265
326
|
},
|
|
327
|
+
tags: [],
|
|
266
328
|
});
|
|
267
329
|
});
|
|
268
330
|
|
|
269
331
|
test('docs with editUrl', async () => {
|
|
270
332
|
const {siteDir, context, options, currentVersion} = await loadSite({
|
|
271
333
|
options: {
|
|
272
|
-
editUrl: 'https://github.com/facebook/docusaurus/edit/
|
|
334
|
+
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
|
273
335
|
},
|
|
274
336
|
});
|
|
275
337
|
|
|
@@ -290,14 +352,29 @@ describe('simple site', () => {
|
|
|
290
352
|
slug: '/foo/bazSlug.html',
|
|
291
353
|
title: 'baz',
|
|
292
354
|
editUrl:
|
|
293
|
-
'https://github.com/facebook/docusaurus/edit/
|
|
355
|
+
'https://github.com/facebook/docusaurus/edit/main/website/docs/foo/baz.md',
|
|
294
356
|
description: 'Images',
|
|
295
357
|
frontMatter: {
|
|
296
358
|
id: 'baz',
|
|
297
359
|
slug: 'bazSlug.html',
|
|
298
360
|
title: 'baz',
|
|
299
361
|
pagination_label: 'baz pagination_label',
|
|
362
|
+
tags: [
|
|
363
|
+
'tag 1',
|
|
364
|
+
'tag-1',
|
|
365
|
+
{label: 'tag 2', permalink: 'tag2-custom-permalink'},
|
|
366
|
+
],
|
|
300
367
|
},
|
|
368
|
+
tags: [
|
|
369
|
+
{
|
|
370
|
+
label: 'tag 1',
|
|
371
|
+
permalink: '/docs/tags/tag-1',
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
label: 'tag 2',
|
|
375
|
+
permalink: '/docs/tags/tag2-custom-permalink',
|
|
376
|
+
},
|
|
377
|
+
],
|
|
301
378
|
});
|
|
302
379
|
});
|
|
303
380
|
|
|
@@ -319,6 +396,7 @@ describe('simple site', () => {
|
|
|
319
396
|
custom_edit_url: 'https://github.com/customUrl/docs/lorem.md',
|
|
320
397
|
unrelated_frontmatter: "won't be part of metadata",
|
|
321
398
|
},
|
|
399
|
+
tags: [],
|
|
322
400
|
});
|
|
323
401
|
});
|
|
324
402
|
|
|
@@ -356,7 +434,22 @@ describe('simple site', () => {
|
|
|
356
434
|
slug: 'bazSlug.html',
|
|
357
435
|
title: 'baz',
|
|
358
436
|
pagination_label: 'baz pagination_label',
|
|
437
|
+
tags: [
|
|
438
|
+
'tag 1',
|
|
439
|
+
'tag-1',
|
|
440
|
+
{label: 'tag 2', permalink: 'tag2-custom-permalink'},
|
|
441
|
+
],
|
|
359
442
|
},
|
|
443
|
+
tags: [
|
|
444
|
+
{
|
|
445
|
+
label: 'tag 1',
|
|
446
|
+
permalink: '/docs/tags/tag-1',
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
label: 'tag 2',
|
|
450
|
+
permalink: '/docs/tags/tag2-custom-permalink',
|
|
451
|
+
},
|
|
452
|
+
],
|
|
360
453
|
});
|
|
361
454
|
|
|
362
455
|
expect(editUrlFunction).toHaveBeenCalledTimes(1);
|
|
@@ -402,6 +495,7 @@ describe('simple site', () => {
|
|
|
402
495
|
lastUpdatedAt: 1539502055,
|
|
403
496
|
formattedLastUpdatedAt: '10/14/2018',
|
|
404
497
|
lastUpdatedBy: 'Author',
|
|
498
|
+
tags: [],
|
|
405
499
|
});
|
|
406
500
|
});
|
|
407
501
|
|
|
@@ -485,6 +579,28 @@ describe('simple site', () => {
|
|
|
485
579
|
`"The docs homepage (homePageId=homePageId) is not allowed to have a frontmatter slug=/x/y => you have to choose either homePageId or slug, not both"`,
|
|
486
580
|
);
|
|
487
581
|
});
|
|
582
|
+
|
|
583
|
+
test('custom pagination', async () => {
|
|
584
|
+
const {defaultTestUtils, options, versionsMetadata} = await loadSite();
|
|
585
|
+
const docs = await readVersionDocs(versionsMetadata[0], options);
|
|
586
|
+
expect(await defaultTestUtils.generateNavigation(docs)).toMatchSnapshot();
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
test('bad pagination', async () => {
|
|
590
|
+
const {defaultTestUtils, options, versionsMetadata} = await loadSite();
|
|
591
|
+
const docs = await readVersionDocs(versionsMetadata[0], options);
|
|
592
|
+
docs.push(
|
|
593
|
+
createFakeDocFile({
|
|
594
|
+
source: 'hehe',
|
|
595
|
+
frontmatter: {pagination_prev: 'nonexistent'},
|
|
596
|
+
}),
|
|
597
|
+
);
|
|
598
|
+
await expect(async () => {
|
|
599
|
+
await defaultTestUtils.generateNavigation(docs);
|
|
600
|
+
}).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
601
|
+
`"Error when loading hehe in .: the pagination_prev front matter points to a non-existent ID nonexistent."`,
|
|
602
|
+
);
|
|
603
|
+
});
|
|
488
604
|
});
|
|
489
605
|
|
|
490
606
|
describe('versioned site', () => {
|
|
@@ -507,12 +623,8 @@ describe('versioned site', () => {
|
|
|
507
623
|
options,
|
|
508
624
|
});
|
|
509
625
|
expect(versionsMetadata.length).toEqual(4);
|
|
510
|
-
const [
|
|
511
|
-
|
|
512
|
-
version101,
|
|
513
|
-
version100,
|
|
514
|
-
versionWithSlugs,
|
|
515
|
-
] = versionsMetadata;
|
|
626
|
+
const [currentVersion, version101, version100, versionWithSlugs] =
|
|
627
|
+
versionsMetadata;
|
|
516
628
|
|
|
517
629
|
const currentVersionTestUtils = createTestUtils({
|
|
518
630
|
siteDir,
|
|
@@ -559,6 +671,7 @@ describe('versioned site', () => {
|
|
|
559
671
|
|
|
560
672
|
await currentVersionTestUtils.testMeta(path.join('foo', 'bar.md'), {
|
|
561
673
|
id: 'foo/bar',
|
|
674
|
+
version: 'current',
|
|
562
675
|
unversionedId: 'foo/bar',
|
|
563
676
|
sourceDirName: 'foo',
|
|
564
677
|
isDocsHomePage: false,
|
|
@@ -566,11 +679,35 @@ describe('versioned site', () => {
|
|
|
566
679
|
slug: '/foo/barSlug',
|
|
567
680
|
title: 'bar',
|
|
568
681
|
description: 'This is next version of bar.',
|
|
569
|
-
frontMatter: {
|
|
570
|
-
|
|
682
|
+
frontMatter: {
|
|
683
|
+
slug: 'barSlug',
|
|
684
|
+
tags: [
|
|
685
|
+
'barTag 1',
|
|
686
|
+
'barTag-2',
|
|
687
|
+
{
|
|
688
|
+
label: 'barTag 3',
|
|
689
|
+
permalink: 'barTag-3-permalink',
|
|
690
|
+
},
|
|
691
|
+
],
|
|
692
|
+
},
|
|
693
|
+
tags: [
|
|
694
|
+
{
|
|
695
|
+
label: 'barTag 1',
|
|
696
|
+
permalink: '/docs/next/tags/bar-tag-1',
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
label: 'barTag-2',
|
|
700
|
+
permalink: '/docs/next/tags/bar-tag-2',
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
label: 'barTag 3',
|
|
704
|
+
permalink: '/docs/next/tags/barTag-3-permalink',
|
|
705
|
+
},
|
|
706
|
+
],
|
|
571
707
|
});
|
|
572
708
|
await currentVersionTestUtils.testMeta(path.join('hello.md'), {
|
|
573
709
|
id: 'hello',
|
|
710
|
+
version: 'current',
|
|
574
711
|
unversionedId: 'hello',
|
|
575
712
|
sourceDirName: '.',
|
|
576
713
|
isDocsHomePage: false,
|
|
@@ -579,7 +716,7 @@ describe('versioned site', () => {
|
|
|
579
716
|
title: 'hello',
|
|
580
717
|
description: 'Hello next !',
|
|
581
718
|
frontMatter: {},
|
|
582
|
-
|
|
719
|
+
tags: [],
|
|
583
720
|
});
|
|
584
721
|
});
|
|
585
722
|
|
|
@@ -597,6 +734,7 @@ describe('versioned site', () => {
|
|
|
597
734
|
description: 'Bar 1.0.0 !',
|
|
598
735
|
frontMatter: {slug: 'barSlug'},
|
|
599
736
|
version: '1.0.0',
|
|
737
|
+
tags: [],
|
|
600
738
|
});
|
|
601
739
|
await version100TestUtils.testMeta(path.join('hello.md'), {
|
|
602
740
|
id: 'version-1.0.0/hello',
|
|
@@ -611,6 +749,7 @@ describe('versioned site', () => {
|
|
|
611
749
|
version: '1.0.0',
|
|
612
750
|
source:
|
|
613
751
|
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
|
|
752
|
+
tags: [],
|
|
614
753
|
});
|
|
615
754
|
await version101TestUtils.testMeta(path.join('foo', 'bar.md'), {
|
|
616
755
|
id: 'version-1.0.1/foo/bar',
|
|
@@ -623,6 +762,7 @@ describe('versioned site', () => {
|
|
|
623
762
|
description: 'Bar 1.0.1 !',
|
|
624
763
|
version: '1.0.1',
|
|
625
764
|
frontMatter: {},
|
|
765
|
+
tags: [],
|
|
626
766
|
});
|
|
627
767
|
await version101TestUtils.testMeta(path.join('hello.md'), {
|
|
628
768
|
id: 'version-1.0.1/hello',
|
|
@@ -635,6 +775,7 @@ describe('versioned site', () => {
|
|
|
635
775
|
description: 'Hello 1.0.1 !',
|
|
636
776
|
version: '1.0.1',
|
|
637
777
|
frontMatter: {},
|
|
778
|
+
tags: [],
|
|
638
779
|
});
|
|
639
780
|
});
|
|
640
781
|
|
|
@@ -729,6 +870,7 @@ describe('versioned site', () => {
|
|
|
729
870
|
source:
|
|
730
871
|
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
|
|
731
872
|
editUrl: hardcodedEditUrl,
|
|
873
|
+
tags: [],
|
|
732
874
|
});
|
|
733
875
|
|
|
734
876
|
expect(editUrlFunction).toHaveBeenCalledTimes(1);
|
|
@@ -744,7 +886,7 @@ describe('versioned site', () => {
|
|
|
744
886
|
test('translated doc with editUrl', async () => {
|
|
745
887
|
const {siteDir, context, options, version100} = await loadSite({
|
|
746
888
|
options: {
|
|
747
|
-
editUrl: 'https://github.com/facebook/docusaurus/edit/
|
|
889
|
+
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
|
748
890
|
// editCurrentVersion: true,
|
|
749
891
|
},
|
|
750
892
|
});
|
|
@@ -770,14 +912,15 @@ describe('versioned site', () => {
|
|
|
770
912
|
source:
|
|
771
913
|
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
|
|
772
914
|
editUrl:
|
|
773
|
-
'https://github.com/facebook/docusaurus/edit/
|
|
915
|
+
'https://github.com/facebook/docusaurus/edit/main/website/versioned_docs/version-1.0.0/hello.md',
|
|
916
|
+
tags: [],
|
|
774
917
|
});
|
|
775
918
|
});
|
|
776
919
|
|
|
777
920
|
test('translated en doc with editUrl and editCurrentVersion=true', async () => {
|
|
778
921
|
const {siteDir, context, options, version100} = await loadSite({
|
|
779
922
|
options: {
|
|
780
|
-
editUrl: 'https://github.com/facebook/docusaurus/edit/
|
|
923
|
+
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
|
781
924
|
editCurrentVersion: true,
|
|
782
925
|
},
|
|
783
926
|
});
|
|
@@ -803,14 +946,15 @@ describe('versioned site', () => {
|
|
|
803
946
|
source:
|
|
804
947
|
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
|
|
805
948
|
editUrl:
|
|
806
|
-
'https://github.com/facebook/docusaurus/edit/
|
|
949
|
+
'https://github.com/facebook/docusaurus/edit/main/website/docs/hello.md',
|
|
950
|
+
tags: [],
|
|
807
951
|
});
|
|
808
952
|
});
|
|
809
953
|
|
|
810
954
|
test('translated fr doc with editUrl and editLocalizedFiles=true', async () => {
|
|
811
955
|
const {siteDir, context, options, version100} = await loadSite({
|
|
812
956
|
options: {
|
|
813
|
-
editUrl: 'https://github.com/facebook/docusaurus/edit/
|
|
957
|
+
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
|
814
958
|
editLocalizedFiles: true,
|
|
815
959
|
},
|
|
816
960
|
locale: 'fr',
|
|
@@ -837,14 +981,15 @@ describe('versioned site', () => {
|
|
|
837
981
|
source:
|
|
838
982
|
'@site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
|
|
839
983
|
editUrl:
|
|
840
|
-
'https://github.com/facebook/docusaurus/edit/
|
|
984
|
+
'https://github.com/facebook/docusaurus/edit/main/website/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
|
|
985
|
+
tags: [],
|
|
841
986
|
});
|
|
842
987
|
});
|
|
843
988
|
|
|
844
989
|
test('translated fr doc with editUrl and editLocalizedFiles=true + editCurrentVersion=true', async () => {
|
|
845
990
|
const {siteDir, context, options, version100} = await loadSite({
|
|
846
991
|
options: {
|
|
847
|
-
editUrl: 'https://github.com/facebook/docusaurus/edit/
|
|
992
|
+
editUrl: 'https://github.com/facebook/docusaurus/edit/main/website',
|
|
848
993
|
editCurrentVersion: true,
|
|
849
994
|
editLocalizedFiles: true,
|
|
850
995
|
},
|
|
@@ -872,7 +1017,8 @@ describe('versioned site', () => {
|
|
|
872
1017
|
source:
|
|
873
1018
|
'@site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
|
|
874
1019
|
editUrl:
|
|
875
|
-
'https://github.com/facebook/docusaurus/edit/
|
|
1020
|
+
'https://github.com/facebook/docusaurus/edit/main/website/i18n/fr/docusaurus-plugin-content-docs/current/hello.md',
|
|
1021
|
+
tags: [],
|
|
876
1022
|
});
|
|
877
1023
|
});
|
|
878
1024
|
});
|
|
@@ -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
|
-
|
|
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 '../
|
|
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) => {
|
|
@@ -347,10 +345,11 @@ describe('simple website', () => {
|
|
|
347
345
|
permalink: '/docs/foo/bar',
|
|
348
346
|
},
|
|
349
347
|
next: {
|
|
350
|
-
title: '
|
|
351
|
-
permalink: '/docs/',
|
|
348
|
+
title: 'rootAbsoluteSlug',
|
|
349
|
+
permalink: '/docs/rootAbsoluteSlug',
|
|
352
350
|
},
|
|
353
351
|
sidebar: 'docs',
|
|
352
|
+
sidebarPosition: undefined,
|
|
354
353
|
source: path.posix.join(
|
|
355
354
|
'@site',
|
|
356
355
|
posixPath(path.relative(siteDir, currentVersion.contentPath)),
|
|
@@ -364,7 +363,23 @@ describe('simple website', () => {
|
|
|
364
363
|
title: 'baz',
|
|
365
364
|
slug: 'bazSlug.html',
|
|
366
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
|
+
],
|
|
367
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
|
+
],
|
|
368
383
|
});
|
|
369
384
|
|
|
370
385
|
expect(findDocById(currentVersion, 'hello')).toEqual({
|
|
@@ -377,8 +392,8 @@ describe('simple website', () => {
|
|
|
377
392
|
permalink: '/docs/',
|
|
378
393
|
slug: '/',
|
|
379
394
|
previous: {
|
|
380
|
-
title: '
|
|
381
|
-
permalink: '/docs/
|
|
395
|
+
title: 'My heading as title',
|
|
396
|
+
permalink: '/docs/headingAsTitle',
|
|
382
397
|
},
|
|
383
398
|
sidebar: 'docs',
|
|
384
399
|
source: path.posix.join(
|
|
@@ -392,7 +407,18 @@ describe('simple website', () => {
|
|
|
392
407
|
id: 'hello',
|
|
393
408
|
title: 'Hello, World !',
|
|
394
409
|
sidebar_label: 'Hello sidebar_label',
|
|
410
|
+
tags: ['tag-1', 'tag 3'],
|
|
395
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
|
+
],
|
|
396
422
|
});
|
|
397
423
|
|
|
398
424
|
expect(getDocById(currentVersion, 'foo/bar')).toEqual({
|
|
@@ -549,12 +575,8 @@ describe('versioned website', () => {
|
|
|
549
575
|
const {siteDir, plugin, pluginContentDir} = await loadSite();
|
|
550
576
|
const content = await plugin.loadContent!();
|
|
551
577
|
expect(content.loadedVersions.length).toEqual(4);
|
|
552
|
-
const [
|
|
553
|
-
|
|
554
|
-
version101,
|
|
555
|
-
version100,
|
|
556
|
-
versionWithSlugs,
|
|
557
|
-
] = content.loadedVersions;
|
|
578
|
+
const [currentVersion, version101, version100, versionWithSlugs] =
|
|
579
|
+
content.loadedVersions;
|
|
558
580
|
|
|
559
581
|
// foo/baz.md only exists in version -1.0.0
|
|
560
582
|
expect(findDocById(currentVersion, 'foo/baz')).toBeUndefined();
|
|
@@ -579,6 +601,11 @@ describe('versioned website', () => {
|
|
|
579
601
|
description: 'This is next version of bar.',
|
|
580
602
|
frontMatter: {
|
|
581
603
|
slug: 'barSlug',
|
|
604
|
+
tags: [
|
|
605
|
+
'barTag 1',
|
|
606
|
+
'barTag-2',
|
|
607
|
+
{label: 'barTag 3', permalink: 'barTag-3-permalink'},
|
|
608
|
+
],
|
|
582
609
|
},
|
|
583
610
|
version: 'current',
|
|
584
611
|
sidebar: 'docs',
|
|
@@ -586,6 +613,11 @@ describe('versioned website', () => {
|
|
|
586
613
|
title: 'hello',
|
|
587
614
|
permalink: '/docs/next/',
|
|
588
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
|
+
],
|
|
589
621
|
});
|
|
590
622
|
expect(getDocById(currentVersion, 'hello')).toEqual({
|
|
591
623
|
...defaultDocMetadata,
|
|
@@ -715,13 +747,8 @@ describe('versioned website (community)', () => {
|
|
|
715
747
|
}
|
|
716
748
|
|
|
717
749
|
test('extendCli - docsVersion', async () => {
|
|
718
|
-
const {
|
|
719
|
-
|
|
720
|
-
routeBasePath,
|
|
721
|
-
sidebarPath,
|
|
722
|
-
pluginId,
|
|
723
|
-
plugin,
|
|
724
|
-
} = await loadSite();
|
|
750
|
+
const {siteDir, routeBasePath, sidebarPath, pluginId, plugin} =
|
|
751
|
+
await loadSite();
|
|
725
752
|
const mock = jest
|
|
726
753
|
.spyOn(cliDocs, 'cliDocsVersionCommand')
|
|
727
754
|
.mockImplementation();
|
|
@@ -1748,12 +1775,11 @@ describe('site with custom sidebar items generator', () => {
|
|
|
1748
1775
|
});
|
|
1749
1776
|
|
|
1750
1777
|
test('sidebar is autogenerated according to a custom sidebarItemsGenerator', async () => {
|
|
1751
|
-
const customSidebarItemsGenerator: SidebarItemsGeneratorOption =
|
|
1752
|
-
|
|
1778
|
+
const customSidebarItemsGenerator: SidebarItemsGeneratorOption =
|
|
1779
|
+
async () => [
|
|
1753
1780
|
{type: 'doc', id: 'API/api-overview'},
|
|
1754
1781
|
{type: 'doc', id: 'API/api-end'},
|
|
1755
1782
|
];
|
|
1756
|
-
};
|
|
1757
1783
|
|
|
1758
1784
|
const {content} = await loadSite(customSidebarItemsGenerator);
|
|
1759
1785
|
const version = content.loadedVersions[0];
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {OptionsSchema, DEFAULT_OPTIONS, validateOptions} from '../options';
|
|
9
9
|
import {normalizePluginOptions} from '@docusaurus/utils-validation';
|
|
10
|
-
import {DefaultSidebarItemsGenerator} from '../
|
|
10
|
+
import {DefaultSidebarItemsGenerator} from '../sidebars/generator';
|
|
11
11
|
import {
|
|
12
12
|
DefaultNumberPrefixParser,
|
|
13
13
|
DisabledNumberPrefixParser,
|
|
@@ -40,6 +40,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|
|
40
40
|
const userOptions = {
|
|
41
41
|
path: 'my-docs', // Path to data on filesystem, relative to site dir.
|
|
42
42
|
routeBasePath: 'my-docs', // URL Route.
|
|
43
|
+
tagsBasePath: 'tags', // URL Tags Route.
|
|
43
44
|
homePageId: 'home', // Document id for docs home page.
|
|
44
45
|
include: ['**/*.{md,mdx}'], // Extensions to include.
|
|
45
46
|
exclude: GlobExcludeDefault,
|
|
@@ -48,6 +49,8 @@ describe('normalizeDocsPluginOptions', () => {
|
|
|
48
49
|
numberPrefixParser: DefaultNumberPrefixParser,
|
|
49
50
|
docLayoutComponent: '@theme/DocPage',
|
|
50
51
|
docItemComponent: '@theme/DocItem',
|
|
52
|
+
docTagDocListComponent: '@theme/DocTagDocListPage',
|
|
53
|
+
docTagsListComponent: '@theme/DocTagsListPage',
|
|
51
54
|
remarkPlugins: [markdownPluginsObjectStub],
|
|
52
55
|
rehypePlugins: [markdownPluginsFunctionStub],
|
|
53
56
|
beforeDefaultRehypePlugins: [],
|
|
@@ -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
|
+
});
|