@docusaurus/plugin-content-docs 2.0.0-beta.1ab8aa0af → 2.0.0-beta.2
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 -4661
- package/lib/cli.js +15 -10
- package/lib/client/docsClientUtils.d.ts +1 -1
- package/lib/client/docsClientUtils.js +3 -10
- package/lib/docFrontMatter.d.ts +1 -14
- package/lib/docFrontMatter.js +3 -2
- package/lib/docs.d.ts +1 -1
- package/lib/docs.js +22 -12
- package/lib/index.js +38 -17
- package/lib/lastUpdate.js +6 -6
- package/lib/markdown/linkify.js +1 -1
- package/lib/options.js +1 -6
- package/lib/props.js +4 -3
- package/lib/sidebarItemsGenerator.js +3 -3
- package/lib/sidebars.d.ts +3 -2
- package/lib/sidebars.js +28 -17
- package/lib/slug.js +2 -2
- package/lib/types.d.ts +18 -5
- package/lib/versions.js +54 -22
- package/package.json +13 -12
- package/src/__tests__/__fixtures__/simple-site/docs/foo/baz.md +4 -1
- package/src/__tests__/__fixtures__/simple-site/docs/hello.md +1 -0
- package/src/__tests__/__snapshots__/index.test.ts.snap +22 -13
- package/src/__tests__/cli.test.ts +16 -16
- package/src/__tests__/docFrontMatter.test.ts +47 -7
- package/src/__tests__/docs.test.ts +8 -5
- package/src/__tests__/index.test.ts +52 -12
- package/src/__tests__/lastUpdate.test.ts +3 -2
- package/src/__tests__/options.test.ts +0 -1
- package/src/__tests__/sidebars.test.ts +9 -8
- package/src/__tests__/versions.test.ts +34 -11
- package/src/cli.ts +17 -11
- package/src/client/__tests__/docsClientUtils.test.ts +6 -7
- package/src/client/docsClientUtils.ts +6 -16
- package/src/docFrontMatter.ts +5 -17
- package/src/docs.ts +28 -10
- package/src/index.ts +58 -21
- package/src/lastUpdate.ts +10 -6
- package/src/markdown/linkify.ts +1 -1
- package/src/options.ts +1 -15
- package/src/plugin-content-docs.d.ts +21 -0
- package/src/props.ts +8 -3
- package/src/sidebarItemsGenerator.ts +3 -3
- package/src/sidebars.ts +52 -19
- package/src/slug.ts +2 -2
- package/src/types.ts +23 -7
- package/src/versions.ts +88 -27
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {validateDocFrontMatter} from '../docFrontMatter';
|
|
9
|
+
import {DocFrontMatter} from '../types';
|
|
10
|
+
import escapeStringRegexp from 'escape-string-regexp';
|
|
9
11
|
|
|
10
12
|
function testField(params: {
|
|
11
13
|
fieldName: keyof DocFrontMatter;
|
|
@@ -38,7 +40,20 @@ function testField(params: {
|
|
|
38
40
|
|
|
39
41
|
test('throw error for values', () => {
|
|
40
42
|
params.invalidFrontMatters?.forEach(([frontMatter, message]) => {
|
|
41
|
-
|
|
43
|
+
try {
|
|
44
|
+
validateDocFrontMatter(frontMatter);
|
|
45
|
+
fail(
|
|
46
|
+
new Error(
|
|
47
|
+
`Doc frontmatter is expected to be rejected, but was accepted successfully:\n ${JSON.stringify(
|
|
48
|
+
frontMatter,
|
|
49
|
+
null,
|
|
50
|
+
2,
|
|
51
|
+
)}`,
|
|
52
|
+
),
|
|
53
|
+
);
|
|
54
|
+
} catch (e) {
|
|
55
|
+
expect(e.message).toMatch(new RegExp(escapeStringRegexp(message)));
|
|
56
|
+
}
|
|
42
57
|
});
|
|
43
58
|
});
|
|
44
59
|
});
|
|
@@ -54,13 +69,17 @@ describe('validateDocFrontMatter', () => {
|
|
|
54
69
|
const frontMatter = {abc: '1'};
|
|
55
70
|
expect(validateDocFrontMatter(frontMatter)).toEqual(frontMatter);
|
|
56
71
|
});
|
|
72
|
+
});
|
|
57
73
|
|
|
74
|
+
describe('validateDocFrontMatter id', () => {
|
|
58
75
|
testField({
|
|
59
76
|
fieldName: 'id',
|
|
60
77
|
validFrontMatters: [{id: '123'}, {id: 'unique_id'}],
|
|
61
78
|
invalidFrontMatters: [[{id: ''}, 'is not allowed to be empty']],
|
|
62
79
|
});
|
|
80
|
+
});
|
|
63
81
|
|
|
82
|
+
describe('validateDocFrontMatter title', () => {
|
|
64
83
|
testField({
|
|
65
84
|
fieldName: 'title',
|
|
66
85
|
validFrontMatters: [
|
|
@@ -69,7 +88,9 @@ describe('validateDocFrontMatter', () => {
|
|
|
69
88
|
{title: 'title'},
|
|
70
89
|
],
|
|
71
90
|
});
|
|
91
|
+
});
|
|
72
92
|
|
|
93
|
+
describe('validateDocFrontMatter hide_title', () => {
|
|
73
94
|
testField({
|
|
74
95
|
fieldName: 'hide_title',
|
|
75
96
|
validFrontMatters: [{hide_title: true}, {hide_title: false}],
|
|
@@ -83,7 +104,9 @@ describe('validateDocFrontMatter', () => {
|
|
|
83
104
|
[{hide_title: ''}, 'must be a boolean'],
|
|
84
105
|
],
|
|
85
106
|
});
|
|
107
|
+
});
|
|
86
108
|
|
|
109
|
+
describe('validateDocFrontMatter hide_table_of_contents', () => {
|
|
87
110
|
testField({
|
|
88
111
|
fieldName: 'hide_table_of_contents',
|
|
89
112
|
validFrontMatters: [
|
|
@@ -100,7 +123,9 @@ describe('validateDocFrontMatter', () => {
|
|
|
100
123
|
[{hide_table_of_contents: ''}, 'must be a boolean'],
|
|
101
124
|
],
|
|
102
125
|
});
|
|
126
|
+
});
|
|
103
127
|
|
|
128
|
+
describe('validateDocFrontMatter keywords', () => {
|
|
104
129
|
testField({
|
|
105
130
|
fieldName: 'keywords',
|
|
106
131
|
validFrontMatters: [
|
|
@@ -115,18 +140,23 @@ describe('validateDocFrontMatter', () => {
|
|
|
115
140
|
[{keywords: []}, 'does not contain 1 required value(s)'],
|
|
116
141
|
],
|
|
117
142
|
});
|
|
143
|
+
});
|
|
118
144
|
|
|
145
|
+
describe('validateDocFrontMatter image', () => {
|
|
119
146
|
testField({
|
|
120
147
|
fieldName: 'image',
|
|
121
|
-
validFrontMatters: [
|
|
148
|
+
validFrontMatters: [
|
|
149
|
+
{image: 'https://docusaurus.io/blog/image.png'},
|
|
150
|
+
{image: '/absolute/image.png'},
|
|
151
|
+
{image: '../relative/image.png'},
|
|
152
|
+
],
|
|
122
153
|
invalidFrontMatters: [
|
|
123
|
-
[{image: ''}, '
|
|
124
|
-
[{image: './api/@docusaurus/plugin-debug'}, 'must be a valid uri'],
|
|
125
|
-
[{image: '/api/@docusaurus/plugin-debug'}, 'must be a valid uri'],
|
|
126
|
-
[{image: '@site/api/asset/image.png'}, 'must be a valid uri'],
|
|
154
|
+
[{image: ''}, 'does not match any of the allowed types'],
|
|
127
155
|
],
|
|
128
156
|
});
|
|
157
|
+
});
|
|
129
158
|
|
|
159
|
+
describe('validateDocFrontMatter description', () => {
|
|
130
160
|
testField({
|
|
131
161
|
fieldName: 'description',
|
|
132
162
|
validFrontMatters: [
|
|
@@ -135,7 +165,9 @@ describe('validateDocFrontMatter', () => {
|
|
|
135
165
|
{description: 'description'},
|
|
136
166
|
],
|
|
137
167
|
});
|
|
168
|
+
});
|
|
138
169
|
|
|
170
|
+
describe('validateDocFrontMatter slug', () => {
|
|
139
171
|
testField({
|
|
140
172
|
fieldName: 'slug',
|
|
141
173
|
validFrontMatters: [
|
|
@@ -150,13 +182,17 @@ describe('validateDocFrontMatter', () => {
|
|
|
150
182
|
],
|
|
151
183
|
invalidFrontMatters: [[{slug: ''}, 'is not allowed to be empty']],
|
|
152
184
|
});
|
|
185
|
+
});
|
|
153
186
|
|
|
187
|
+
describe('validateDocFrontMatter sidebar_label', () => {
|
|
154
188
|
testField({
|
|
155
189
|
fieldName: 'sidebar_label',
|
|
156
190
|
validFrontMatters: [{sidebar_label: 'Awesome docs'}],
|
|
157
191
|
invalidFrontMatters: [[{sidebar_label: ''}, 'is not allowed to be empty']],
|
|
158
192
|
});
|
|
193
|
+
});
|
|
159
194
|
|
|
195
|
+
describe('validateDocFrontMatter sidebar_position', () => {
|
|
160
196
|
testField({
|
|
161
197
|
fieldName: 'sidebar_position',
|
|
162
198
|
validFrontMatters: [
|
|
@@ -172,7 +208,9 @@ describe('validateDocFrontMatter', () => {
|
|
|
172
208
|
[{sidebar_position: -1}, 'must be greater than or equal to 0'],
|
|
173
209
|
],
|
|
174
210
|
});
|
|
211
|
+
});
|
|
175
212
|
|
|
213
|
+
describe('validateDocFrontMatter custom_edit_url', () => {
|
|
176
214
|
testField({
|
|
177
215
|
fieldName: 'custom_edit_url',
|
|
178
216
|
validFrontMatters: [
|
|
@@ -184,7 +222,9 @@ describe('validateDocFrontMatter', () => {
|
|
|
184
222
|
{custom_edit_url: '@site/api/docs/markdown.md'},
|
|
185
223
|
],
|
|
186
224
|
});
|
|
225
|
+
});
|
|
187
226
|
|
|
227
|
+
describe('validateDocFrontMatter parse_number_prefixes', () => {
|
|
188
228
|
testField({
|
|
189
229
|
fieldName: 'parse_number_prefixes',
|
|
190
230
|
validFrontMatters: [
|
|
@@ -76,7 +76,7 @@ function createTestUtils({
|
|
|
76
76
|
docFileSource: string,
|
|
77
77
|
expectedMetadata: Optional<
|
|
78
78
|
DocMetadataBase,
|
|
79
|
-
'source' | 'lastUpdatedBy' | 'lastUpdatedAt' | '
|
|
79
|
+
'source' | 'lastUpdatedBy' | 'lastUpdatedAt' | 'editUrl'
|
|
80
80
|
>,
|
|
81
81
|
) {
|
|
82
82
|
const docFile = await readDoc(docFileSource);
|
|
@@ -89,7 +89,6 @@ function createTestUtils({
|
|
|
89
89
|
expect(metadata).toEqual({
|
|
90
90
|
lastUpdatedBy: undefined,
|
|
91
91
|
lastUpdatedAt: undefined,
|
|
92
|
-
sidebar_label: undefined,
|
|
93
92
|
editUrl: undefined,
|
|
94
93
|
source: path.posix.join(
|
|
95
94
|
'@site',
|
|
@@ -181,7 +180,7 @@ describe('simple site', () => {
|
|
|
181
180
|
isDocsHomePage: false,
|
|
182
181
|
permalink: '/docs/foo/bar',
|
|
183
182
|
slug: '/foo/bar',
|
|
184
|
-
title: '
|
|
183
|
+
title: 'Bar',
|
|
185
184
|
description: 'This is custom description',
|
|
186
185
|
frontMatter: {
|
|
187
186
|
description: 'This is custom description',
|
|
@@ -202,6 +201,7 @@ describe('simple site', () => {
|
|
|
202
201
|
frontMatter: {
|
|
203
202
|
id: 'hello',
|
|
204
203
|
title: 'Hello, World !',
|
|
204
|
+
sidebar_label: 'Hello sidebar_label',
|
|
205
205
|
},
|
|
206
206
|
});
|
|
207
207
|
});
|
|
@@ -231,6 +231,7 @@ describe('simple site', () => {
|
|
|
231
231
|
frontMatter: {
|
|
232
232
|
id: 'hello',
|
|
233
233
|
title: 'Hello, World !',
|
|
234
|
+
sidebar_label: 'Hello sidebar_label',
|
|
234
235
|
},
|
|
235
236
|
});
|
|
236
237
|
});
|
|
@@ -255,7 +256,7 @@ describe('simple site', () => {
|
|
|
255
256
|
isDocsHomePage: true,
|
|
256
257
|
permalink: '/docs/',
|
|
257
258
|
slug: '/',
|
|
258
|
-
title: '
|
|
259
|
+
title: 'Bar',
|
|
259
260
|
description: 'This is custom description',
|
|
260
261
|
frontMatter: {
|
|
261
262
|
description: 'This is custom description',
|
|
@@ -295,6 +296,7 @@ describe('simple site', () => {
|
|
|
295
296
|
id: 'baz',
|
|
296
297
|
slug: 'bazSlug.html',
|
|
297
298
|
title: 'baz',
|
|
299
|
+
pagination_label: 'baz pagination_label',
|
|
298
300
|
},
|
|
299
301
|
});
|
|
300
302
|
});
|
|
@@ -353,6 +355,7 @@ describe('simple site', () => {
|
|
|
353
355
|
id: 'baz',
|
|
354
356
|
slug: 'bazSlug.html',
|
|
355
357
|
title: 'baz',
|
|
358
|
+
pagination_label: 'baz pagination_label',
|
|
356
359
|
},
|
|
357
360
|
});
|
|
358
361
|
|
|
@@ -452,7 +455,7 @@ describe('simple site', () => {
|
|
|
452
455
|
}),
|
|
453
456
|
);
|
|
454
457
|
}).toThrowErrorMatchingInlineSnapshot(
|
|
455
|
-
`"Document id
|
|
458
|
+
`"Document id \\"Hello/world\\" cannot include slash."`,
|
|
456
459
|
);
|
|
457
460
|
});
|
|
458
461
|
|
|
@@ -44,8 +44,10 @@ function getDocById(version: LoadedVersion, unversionedId: string) {
|
|
|
44
44
|
const doc = findDocById(version, unversionedId);
|
|
45
45
|
if (!doc) {
|
|
46
46
|
throw new Error(
|
|
47
|
-
`No doc found with id
|
|
48
|
-
|
|
47
|
+
`No doc found with id "${unversionedId}" in version ${
|
|
48
|
+
version.versionName
|
|
49
|
+
}.
|
|
50
|
+
Available ids are:\n- ${version.docs.map((d) => d.unversionedId).join('\n- ')}`,
|
|
49
51
|
);
|
|
50
52
|
}
|
|
51
53
|
return doc;
|
|
@@ -57,7 +59,6 @@ const defaultDocMetadata: Partial<DocMetadata> = {
|
|
|
57
59
|
editUrl: undefined,
|
|
58
60
|
lastUpdatedAt: undefined,
|
|
59
61
|
lastUpdatedBy: undefined,
|
|
60
|
-
sidebar_label: undefined,
|
|
61
62
|
formattedLastUpdatedAt: undefined,
|
|
62
63
|
};
|
|
63
64
|
|
|
@@ -86,7 +87,7 @@ const createFakeActions = (contentDir: string) => {
|
|
|
86
87
|
key.startsWith(prefix),
|
|
87
88
|
);
|
|
88
89
|
if (!entry) {
|
|
89
|
-
throw new Error(`No created entry found for prefix
|
|
90
|
+
throw new Error(`No created entry found for prefix "${prefix}".
|
|
90
91
|
Entries created:
|
|
91
92
|
- ${Object.keys(dataContainer).join('\n- ')}
|
|
92
93
|
`);
|
|
@@ -152,8 +153,8 @@ describe('sidebar', () => {
|
|
|
152
153
|
);
|
|
153
154
|
await plugin.loadContent!();
|
|
154
155
|
}).rejects.toThrowErrorMatchingInlineSnapshot(`
|
|
155
|
-
"The path to the sidebar file does not exist at
|
|
156
|
-
Please set the docs
|
|
156
|
+
"The path to the sidebar file does not exist at \\"wrong-path-sidebar.json\\".
|
|
157
|
+
Please set the docs \\"sidebarPath\\" field in your config file to:
|
|
157
158
|
- a sidebars path that exists
|
|
158
159
|
- false: to disable the sidebar
|
|
159
160
|
- undefined: for Docusaurus generates it automatically"
|
|
@@ -218,7 +219,7 @@ describe('empty/no docs website', () => {
|
|
|
218
219
|
await expect(
|
|
219
220
|
plugin.loadContent!(),
|
|
220
221
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
221
|
-
`"Docs version current has no docs! At least one doc should exist at
|
|
222
|
+
`"Docs version \\"current\\" has no docs! At least one doc should exist at \\"docs\\"."`,
|
|
222
223
|
);
|
|
223
224
|
});
|
|
224
225
|
|
|
@@ -232,11 +233,11 @@ describe('empty/no docs website', () => {
|
|
|
232
233
|
}),
|
|
233
234
|
),
|
|
234
235
|
).toThrowError(
|
|
235
|
-
`The docs folder does not exist for version
|
|
236
|
+
`The docs folder does not exist for version "current". A docs folder is expected to be found at ${
|
|
236
237
|
process.platform === 'win32'
|
|
237
238
|
? 'path\\doesnt\\exist'
|
|
238
239
|
: 'path/doesnt/exist'
|
|
239
|
-
}
|
|
240
|
+
}.`,
|
|
240
241
|
);
|
|
241
242
|
});
|
|
242
243
|
});
|
|
@@ -308,6 +309,8 @@ describe('simple website', () => {
|
|
|
308
309
|
test('configureWebpack', async () => {
|
|
309
310
|
const {plugin} = await loadSite();
|
|
310
311
|
|
|
312
|
+
const content = await plugin.loadContent?.();
|
|
313
|
+
|
|
311
314
|
const config = applyConfigureWebpack(
|
|
312
315
|
plugin.configureWebpack,
|
|
313
316
|
{
|
|
@@ -318,6 +321,8 @@ describe('simple website', () => {
|
|
|
318
321
|
},
|
|
319
322
|
},
|
|
320
323
|
false,
|
|
324
|
+
undefined,
|
|
325
|
+
content,
|
|
321
326
|
);
|
|
322
327
|
const errors = validate(config);
|
|
323
328
|
expect(errors).toBeUndefined();
|
|
@@ -329,6 +334,40 @@ describe('simple website', () => {
|
|
|
329
334
|
expect(content.loadedVersions.length).toEqual(1);
|
|
330
335
|
const [currentVersion] = content.loadedVersions;
|
|
331
336
|
|
|
337
|
+
expect(findDocById(currentVersion, 'foo/baz')).toEqual({
|
|
338
|
+
...defaultDocMetadata,
|
|
339
|
+
version: 'current',
|
|
340
|
+
id: 'foo/baz',
|
|
341
|
+
unversionedId: 'foo/baz',
|
|
342
|
+
sourceDirName: 'foo',
|
|
343
|
+
isDocsHomePage: false,
|
|
344
|
+
permalink: '/docs/foo/bazSlug.html',
|
|
345
|
+
slug: '/foo/bazSlug.html',
|
|
346
|
+
previous: {
|
|
347
|
+
title: 'Bar',
|
|
348
|
+
permalink: '/docs/foo/bar',
|
|
349
|
+
},
|
|
350
|
+
next: {
|
|
351
|
+
title: 'Hello sidebar_label',
|
|
352
|
+
permalink: '/docs/',
|
|
353
|
+
},
|
|
354
|
+
sidebar: 'docs',
|
|
355
|
+
source: path.posix.join(
|
|
356
|
+
'@site',
|
|
357
|
+
posixPath(path.relative(siteDir, currentVersion.contentPath)),
|
|
358
|
+
'foo',
|
|
359
|
+
'baz.md',
|
|
360
|
+
),
|
|
361
|
+
title: 'baz',
|
|
362
|
+
description: 'Images',
|
|
363
|
+
frontMatter: {
|
|
364
|
+
id: 'baz',
|
|
365
|
+
title: 'baz',
|
|
366
|
+
slug: 'bazSlug.html',
|
|
367
|
+
pagination_label: 'baz pagination_label',
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
|
|
332
371
|
expect(findDocById(currentVersion, 'hello')).toEqual({
|
|
333
372
|
...defaultDocMetadata,
|
|
334
373
|
version: 'current',
|
|
@@ -339,7 +378,7 @@ describe('simple website', () => {
|
|
|
339
378
|
permalink: '/docs/',
|
|
340
379
|
slug: '/',
|
|
341
380
|
previous: {
|
|
342
|
-
title: 'baz',
|
|
381
|
+
title: 'baz pagination_label',
|
|
343
382
|
permalink: '/docs/foo/bazSlug.html',
|
|
344
383
|
},
|
|
345
384
|
sidebar: 'docs',
|
|
@@ -353,6 +392,7 @@ describe('simple website', () => {
|
|
|
353
392
|
frontMatter: {
|
|
354
393
|
id: 'hello',
|
|
355
394
|
title: 'Hello, World !',
|
|
395
|
+
sidebar_label: 'Hello sidebar_label',
|
|
356
396
|
},
|
|
357
397
|
});
|
|
358
398
|
|
|
@@ -364,7 +404,7 @@ describe('simple website', () => {
|
|
|
364
404
|
sourceDirName: 'foo',
|
|
365
405
|
isDocsHomePage: false,
|
|
366
406
|
next: {
|
|
367
|
-
title: 'baz',
|
|
407
|
+
title: 'baz pagination_label',
|
|
368
408
|
permalink: '/docs/foo/bazSlug.html',
|
|
369
409
|
},
|
|
370
410
|
permalink: '/docs/foo/bar',
|
|
@@ -376,7 +416,7 @@ describe('simple website', () => {
|
|
|
376
416
|
'foo',
|
|
377
417
|
'bar.md',
|
|
378
418
|
),
|
|
379
|
-
title: '
|
|
419
|
+
title: 'Bar',
|
|
380
420
|
description: 'This is custom description',
|
|
381
421
|
frontMatter: {
|
|
382
422
|
description: 'This is custom description',
|
|
@@ -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
|
-
`Command failed with exit code 128: git log -1 --format=%ct, %an ${
|
|
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();
|
|
@@ -60,7 +60,7 @@ describe('loadSidebars', () => {
|
|
|
60
60
|
'sidebars-category-wrong-items.json',
|
|
61
61
|
);
|
|
62
62
|
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
|
63
|
-
`"Error loading {\\"type\\":\\"category\\",\\"label\\":\\"Category Label\\",\\"items\\":\\"doc1\\"}
|
|
63
|
+
`"Error loading {\\"type\\":\\"category\\",\\"label\\":\\"Category Label\\",\\"items\\":\\"doc1\\"}: \\"items\\" must be an array."`,
|
|
64
64
|
);
|
|
65
65
|
});
|
|
66
66
|
|
|
@@ -70,7 +70,7 @@ describe('loadSidebars', () => {
|
|
|
70
70
|
'sidebars-category-wrong-label.json',
|
|
71
71
|
);
|
|
72
72
|
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
|
73
|
-
`"Error loading {\\"type\\":\\"category\\",\\"label\\":true,\\"items\\":[\\"doc1\\"]}
|
|
73
|
+
`"Error loading {\\"type\\":\\"category\\",\\"label\\":true,\\"items\\":[\\"doc1\\"]}: \\"label\\" must be a string."`,
|
|
74
74
|
);
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -80,7 +80,7 @@ describe('loadSidebars', () => {
|
|
|
80
80
|
'sidebars-doc-id-not-string.json',
|
|
81
81
|
);
|
|
82
82
|
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
|
83
|
-
`"Error loading {\\"type\\":\\"doc\\",\\"id\\":[\\"doc1\\"]}
|
|
83
|
+
`"Error loading {\\"type\\":\\"doc\\",\\"id\\":[\\"doc1\\"]}: \\"id\\" must be a string."`,
|
|
84
84
|
);
|
|
85
85
|
});
|
|
86
86
|
|
|
@@ -102,22 +102,23 @@ describe('loadSidebars', () => {
|
|
|
102
102
|
test('sidebars link wrong label', async () => {
|
|
103
103
|
const sidebarPath = path.join(fixtureDir, 'sidebars-link-wrong-label.json');
|
|
104
104
|
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
|
105
|
-
`"Error loading {\\"type\\":\\"link\\",\\"label\\":false,\\"href\\":\\"https://github.com\\"}
|
|
105
|
+
`"Error loading {\\"type\\":\\"link\\",\\"label\\":false,\\"href\\":\\"https://github.com\\"}: \\"label\\" must be a string."`,
|
|
106
106
|
);
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
test('sidebars link wrong href', async () => {
|
|
110
110
|
const sidebarPath = path.join(fixtureDir, 'sidebars-link-wrong-href.json');
|
|
111
111
|
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
|
112
|
-
`"Error loading {\\"type\\":\\"link\\",\\"label\\":\\"GitHub\\",\\"href\\":[\\"example.com\\"]}
|
|
112
|
+
`"Error loading {\\"type\\":\\"link\\",\\"label\\":\\"GitHub\\",\\"href\\":[\\"example.com\\"]}: \\"href\\" must be a string."`,
|
|
113
113
|
);
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
test('sidebars with unknown sidebar item type', async () => {
|
|
117
117
|
const sidebarPath = path.join(fixtureDir, 'sidebars-unknown-type.json');
|
|
118
|
-
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(`
|
|
119
|
+
"Unknown sidebar item type \\"superman\\". Sidebar item is {\\"type\\":\\"superman\\"}.
|
|
120
|
+
"
|
|
121
|
+
`);
|
|
121
122
|
});
|
|
122
123
|
|
|
123
124
|
test('sidebars with known sidebar item type but wrong field', async () => {
|
|
@@ -21,6 +21,7 @@ const DefaultI18N: I18n = {
|
|
|
21
21
|
currentLocale: 'en',
|
|
22
22
|
locales: ['en'],
|
|
23
23
|
defaultLocale: 'en',
|
|
24
|
+
localeConfigs: {},
|
|
24
25
|
};
|
|
25
26
|
|
|
26
27
|
describe('version paths', () => {
|
|
@@ -79,6 +80,7 @@ describe('simple site', () => {
|
|
|
79
80
|
versionLabel: 'Next',
|
|
80
81
|
versionName: 'current',
|
|
81
82
|
versionPath: '/docs',
|
|
83
|
+
versionBanner: 'none',
|
|
82
84
|
};
|
|
83
85
|
return {simpleSiteDir, defaultOptions, defaultContext, vCurrent};
|
|
84
86
|
}
|
|
@@ -174,7 +176,7 @@ describe('simple site', () => {
|
|
|
174
176
|
context: defaultContext,
|
|
175
177
|
}),
|
|
176
178
|
).toThrowErrorMatchingInlineSnapshot(
|
|
177
|
-
`"
|
|
179
|
+
`"Invalid docs option \\"versions\\": unknown versions (unknownVersionName1,unknownVersionName2) found. Available version names are: current"`,
|
|
178
180
|
);
|
|
179
181
|
});
|
|
180
182
|
|
|
@@ -187,7 +189,7 @@ describe('simple site', () => {
|
|
|
187
189
|
context: defaultContext,
|
|
188
190
|
}),
|
|
189
191
|
).toThrowErrorMatchingInlineSnapshot(
|
|
190
|
-
`"Docs: using disableVersioning=true option on a non-versioned site does not make sense"`,
|
|
192
|
+
`"Docs: using \\"disableVersioning=true\\" option on a non-versioned site does not make sense."`,
|
|
191
193
|
);
|
|
192
194
|
});
|
|
193
195
|
|
|
@@ -200,7 +202,7 @@ describe('simple site', () => {
|
|
|
200
202
|
context: defaultContext,
|
|
201
203
|
}),
|
|
202
204
|
).toThrowErrorMatchingInlineSnapshot(
|
|
203
|
-
`"It is not possible to use docs without any version. Please check the configuration of these options: includeCurrentVersion=false disableVersioning=false"`,
|
|
205
|
+
`"It is not possible to use docs without any version. Please check the configuration of these options: \\"includeCurrentVersion=false\\", \\"disableVersioning=false\\"."`,
|
|
204
206
|
);
|
|
205
207
|
});
|
|
206
208
|
});
|
|
@@ -233,6 +235,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
233
235
|
versionLabel: 'Next',
|
|
234
236
|
versionName: 'current',
|
|
235
237
|
versionPath: '/docs/next',
|
|
238
|
+
versionBanner: 'unreleased',
|
|
236
239
|
};
|
|
237
240
|
|
|
238
241
|
const v101: VersionMetadata = {
|
|
@@ -250,6 +253,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
250
253
|
versionLabel: '1.0.1',
|
|
251
254
|
versionName: '1.0.1',
|
|
252
255
|
versionPath: '/docs',
|
|
256
|
+
versionBanner: 'none',
|
|
253
257
|
};
|
|
254
258
|
|
|
255
259
|
const v100: VersionMetadata = {
|
|
@@ -267,6 +271,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
267
271
|
versionLabel: '1.0.0',
|
|
268
272
|
versionName: '1.0.0',
|
|
269
273
|
versionPath: '/docs/1.0.0',
|
|
274
|
+
versionBanner: 'unmaintained',
|
|
270
275
|
};
|
|
271
276
|
|
|
272
277
|
const vwithSlugs: VersionMetadata = {
|
|
@@ -287,6 +292,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
287
292
|
versionLabel: 'withSlugs',
|
|
288
293
|
versionName: 'withSlugs',
|
|
289
294
|
versionPath: '/docs/withSlugs',
|
|
295
|
+
versionBanner: 'unmaintained',
|
|
290
296
|
};
|
|
291
297
|
|
|
292
298
|
return {
|
|
@@ -357,9 +363,11 @@ describe('versioned site, pluginId=default', () => {
|
|
|
357
363
|
versions: {
|
|
358
364
|
current: {
|
|
359
365
|
path: 'current-path',
|
|
366
|
+
banner: 'unmaintained',
|
|
360
367
|
},
|
|
361
368
|
'1.0.0': {
|
|
362
369
|
label: '1.0.0-label',
|
|
370
|
+
banner: 'unreleased',
|
|
363
371
|
},
|
|
364
372
|
},
|
|
365
373
|
},
|
|
@@ -367,12 +375,17 @@ describe('versioned site, pluginId=default', () => {
|
|
|
367
375
|
});
|
|
368
376
|
|
|
369
377
|
expect(versionsMetadata).toEqual([
|
|
370
|
-
{
|
|
378
|
+
{
|
|
379
|
+
...vCurrent,
|
|
380
|
+
versionPath: '/docs/current-path',
|
|
381
|
+
versionBanner: 'unmaintained',
|
|
382
|
+
},
|
|
371
383
|
{
|
|
372
384
|
...v101,
|
|
373
385
|
isLast: false,
|
|
374
386
|
routePriority: undefined,
|
|
375
387
|
versionPath: '/docs/1.0.1',
|
|
388
|
+
versionBanner: 'unreleased',
|
|
376
389
|
},
|
|
377
390
|
{
|
|
378
391
|
...v100,
|
|
@@ -380,6 +393,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
380
393
|
routePriority: -1,
|
|
381
394
|
versionLabel: '1.0.0-label',
|
|
382
395
|
versionPath: '/docs',
|
|
396
|
+
versionBanner: 'unreleased',
|
|
383
397
|
},
|
|
384
398
|
vwithSlugs,
|
|
385
399
|
]);
|
|
@@ -510,7 +524,13 @@ describe('versioned site, pluginId=default', () => {
|
|
|
510
524
|
});
|
|
511
525
|
|
|
512
526
|
expect(versionsMetadata).toEqual([
|
|
513
|
-
{
|
|
527
|
+
{
|
|
528
|
+
...vCurrent,
|
|
529
|
+
isLast: true,
|
|
530
|
+
routePriority: -1,
|
|
531
|
+
versionPath: '/docs',
|
|
532
|
+
versionBanner: 'none',
|
|
533
|
+
},
|
|
514
534
|
]);
|
|
515
535
|
});
|
|
516
536
|
|
|
@@ -527,7 +547,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
527
547
|
context: defaultContext,
|
|
528
548
|
}),
|
|
529
549
|
).toThrowErrorMatchingInlineSnapshot(
|
|
530
|
-
`"It is not possible to use docs without any version. Please check the configuration of these options: includeCurrentVersion=false disableVersioning=true"`,
|
|
550
|
+
`"It is not possible to use docs without any version. Please check the configuration of these options: \\"includeCurrentVersion=false\\", \\"disableVersioning=true\\"."`,
|
|
531
551
|
);
|
|
532
552
|
});
|
|
533
553
|
|
|
@@ -543,7 +563,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
543
563
|
context: defaultContext,
|
|
544
564
|
}),
|
|
545
565
|
).toThrowErrorMatchingInlineSnapshot(
|
|
546
|
-
`"
|
|
566
|
+
`"Invalid docs option \\"onlyIncludeVersions\\": an empty array is not allowed, at least one version is needed."`,
|
|
547
567
|
);
|
|
548
568
|
});
|
|
549
569
|
|
|
@@ -559,7 +579,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
559
579
|
context: defaultContext,
|
|
560
580
|
}),
|
|
561
581
|
).toThrowErrorMatchingInlineSnapshot(
|
|
562
|
-
`"
|
|
582
|
+
`"Invalid docs option \\"onlyIncludeVersions\\": unknown versions (unknownVersion1,unknownVersion2) found. Available version names are: current, 1.0.1, 1.0.0, withSlugs"`,
|
|
563
583
|
);
|
|
564
584
|
});
|
|
565
585
|
|
|
@@ -576,7 +596,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
576
596
|
context: defaultContext,
|
|
577
597
|
}),
|
|
578
598
|
).toThrowErrorMatchingInlineSnapshot(
|
|
579
|
-
`"
|
|
599
|
+
`"Invalid docs option \\"lastVersion\\": if you use both the \\"onlyIncludeVersions\\" and \\"lastVersion\\" options, then \\"lastVersion\\" must be present in the provided \\"onlyIncludeVersions\\" array."`,
|
|
580
600
|
);
|
|
581
601
|
});
|
|
582
602
|
|
|
@@ -595,7 +615,7 @@ describe('versioned site, pluginId=default', () => {
|
|
|
595
615
|
context: defaultContext,
|
|
596
616
|
});
|
|
597
617
|
}).toThrowErrorMatchingInlineSnapshot(
|
|
598
|
-
`"The versions file should contain an array of versions! Found content
|
|
618
|
+
`"The versions file should contain an array of versions! Found content: {\\"invalid\\":\\"json\\"}"`,
|
|
599
619
|
);
|
|
600
620
|
mock.mockRestore();
|
|
601
621
|
});
|
|
@@ -631,6 +651,7 @@ describe('versioned site, pluginId=community', () => {
|
|
|
631
651
|
versionLabel: 'Next',
|
|
632
652
|
versionName: 'current',
|
|
633
653
|
versionPath: '/communityBasePath/next',
|
|
654
|
+
versionBanner: 'unreleased',
|
|
634
655
|
};
|
|
635
656
|
|
|
636
657
|
const v100: VersionMetadata = {
|
|
@@ -651,6 +672,7 @@ describe('versioned site, pluginId=community', () => {
|
|
|
651
672
|
versionLabel: '1.0.0',
|
|
652
673
|
versionName: '1.0.0',
|
|
653
674
|
versionPath: '/communityBasePath',
|
|
675
|
+
versionBanner: 'none',
|
|
654
676
|
};
|
|
655
677
|
|
|
656
678
|
return {versionedSiteDir, defaultOptions, defaultContext, vCurrent, v100};
|
|
@@ -695,6 +717,7 @@ describe('versioned site, pluginId=community', () => {
|
|
|
695
717
|
isLast: true,
|
|
696
718
|
routePriority: -1,
|
|
697
719
|
versionPath: '/communityBasePath',
|
|
720
|
+
versionBanner: 'none',
|
|
698
721
|
},
|
|
699
722
|
]);
|
|
700
723
|
});
|
|
@@ -712,7 +735,7 @@ describe('versioned site, pluginId=community', () => {
|
|
|
712
735
|
context: defaultContext,
|
|
713
736
|
}),
|
|
714
737
|
).toThrowErrorMatchingInlineSnapshot(
|
|
715
|
-
`"It is not possible to use docs without any version. Please check the configuration of these options: includeCurrentVersion=false disableVersioning=true"`,
|
|
738
|
+
`"It is not possible to use docs without any version. Please check the configuration of these options: \\"includeCurrentVersion=false\\", \\"disableVersioning=true\\"."`,
|
|
716
739
|
);
|
|
717
740
|
});
|
|
718
741
|
});
|