@docusaurus/plugin-content-docs 0.0.0-4235 → 0.0.0-4242
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.js +5 -23
- package/lib/docs.d.ts +22 -2
- package/lib/docs.js +71 -29
- package/lib/index.js +34 -62
- package/lib/options.js +2 -0
- package/lib/props.js +35 -6
- package/lib/routes.d.ts +27 -0
- package/lib/routes.js +105 -0
- package/lib/sidebars/generator.d.ts +2 -1
- package/lib/sidebars/generator.js +55 -13
- package/lib/sidebars/index.d.ts +5 -4
- package/lib/sidebars/index.js +18 -9
- package/lib/sidebars/normalization.d.ts +8 -3
- package/lib/sidebars/normalization.js +36 -17
- package/lib/sidebars/processor.d.ts +5 -3
- package/lib/sidebars/processor.js +33 -18
- package/lib/sidebars/types.d.ts +43 -2
- package/lib/sidebars/utils.d.ts +18 -6
- package/lib/sidebars/utils.js +149 -24
- package/lib/sidebars/validation.d.ts +2 -0
- package/lib/sidebars/validation.js +44 -8
- package/lib/slug.d.ts +4 -3
- package/lib/slug.js +26 -14
- package/lib/translations.js +51 -7
- package/lib/types.d.ts +18 -3
- package/package.json +8 -8
- 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 -106
- package/src/__tests__/__snapshots__/index.test.ts.snap +279 -28
- package/src/__tests__/__snapshots__/translations.test.ts.snap +45 -0
- package/src/__tests__/docs.test.ts +122 -7
- package/src/__tests__/index.test.ts +27 -1
- package/src/__tests__/options.test.ts +2 -0
- package/src/__tests__/slug.test.ts +127 -20
- package/src/__tests__/translations.test.ts +7 -0
- package/src/categoryGeneratedIndex.ts +57 -0
- package/src/cli.ts +5 -35
- package/src/docs.ts +103 -45
- package/src/index.ts +55 -93
- package/src/options.ts +4 -0
- package/src/plugin-content-docs.d.ts +71 -8
- package/src/props.ts +48 -9
- package/src/routes.ts +173 -0
- package/src/sidebars/__tests__/__snapshots__/index.test.ts.snap +21 -6
- package/src/sidebars/__tests__/generator.test.ts +105 -1
- package/src/sidebars/__tests__/index.test.ts +26 -24
- package/src/sidebars/__tests__/processor.test.ts +110 -19
- package/src/sidebars/__tests__/utils.test.ts +320 -20
- package/src/sidebars/__tests__/validation.test.ts +105 -0
- package/src/sidebars/generator.ts +82 -19
- package/src/sidebars/index.ts +23 -13
- package/src/sidebars/normalization.ts +47 -23
- package/src/sidebars/processor.ts +57 -27
- package/src/sidebars/types.ts +64 -3
- package/src/sidebars/utils.ts +217 -42
- package/src/sidebars/validation.ts +52 -8
- package/src/slug.ts +32 -17
- package/src/translations.ts +74 -8
- package/src/types.ts +22 -5
|
@@ -7,27 +7,31 @@
|
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
loadNormalizedSidebars,
|
|
11
11
|
DefaultSidebars,
|
|
12
12
|
DisabledSidebars,
|
|
13
13
|
} from '../index';
|
|
14
|
-
import type {
|
|
14
|
+
import type {NormalizeSidebarsParams, VersionMetadata} from '../../types';
|
|
15
15
|
|
|
16
|
-
describe('
|
|
16
|
+
describe('loadNormalizedSidebars', () => {
|
|
17
17
|
const fixtureDir = path.join(__dirname, '__fixtures__', 'sidebars');
|
|
18
|
-
const options:
|
|
18
|
+
const options: NormalizeSidebarsParams = {
|
|
19
19
|
sidebarCollapsed: true,
|
|
20
20
|
sidebarCollapsible: true,
|
|
21
|
+
version: {
|
|
22
|
+
versionName: 'version',
|
|
23
|
+
versionPath: 'versionPath',
|
|
24
|
+
} as VersionMetadata,
|
|
21
25
|
};
|
|
22
26
|
test('sidebars with known sidebar item type', async () => {
|
|
23
27
|
const sidebarPath = path.join(fixtureDir, 'sidebars.json');
|
|
24
|
-
const result =
|
|
28
|
+
const result = loadNormalizedSidebars(sidebarPath, options);
|
|
25
29
|
expect(result).toMatchSnapshot();
|
|
26
30
|
});
|
|
27
31
|
|
|
28
32
|
test('sidebars with deep level of category', async () => {
|
|
29
33
|
const sidebarPath = path.join(fixtureDir, 'sidebars-category.js');
|
|
30
|
-
const result =
|
|
34
|
+
const result = loadNormalizedSidebars(sidebarPath, options);
|
|
31
35
|
expect(result).toMatchSnapshot();
|
|
32
36
|
});
|
|
33
37
|
|
|
@@ -37,8 +41,8 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
37
41
|
fixtureDir,
|
|
38
42
|
'sidebars-category-shorthand.js',
|
|
39
43
|
);
|
|
40
|
-
const sidebar1 =
|
|
41
|
-
const sidebar2 =
|
|
44
|
+
const sidebar1 = loadNormalizedSidebars(sidebarPath1, options);
|
|
45
|
+
const sidebar2 = loadNormalizedSidebars(sidebarPath2, options);
|
|
42
46
|
expect(sidebar1).toEqual(sidebar2);
|
|
43
47
|
});
|
|
44
48
|
|
|
@@ -47,7 +51,7 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
47
51
|
fixtureDir,
|
|
48
52
|
'sidebars-category-wrong-items.json',
|
|
49
53
|
);
|
|
50
|
-
expect(() =>
|
|
54
|
+
expect(() => loadNormalizedSidebars(sidebarPath, options))
|
|
51
55
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
52
56
|
"{
|
|
53
57
|
\\"type\\": \\"category\\",
|
|
@@ -64,7 +68,7 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
64
68
|
fixtureDir,
|
|
65
69
|
'sidebars-category-wrong-label.json',
|
|
66
70
|
);
|
|
67
|
-
expect(() =>
|
|
71
|
+
expect(() => loadNormalizedSidebars(sidebarPath, options))
|
|
68
72
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
69
73
|
"{
|
|
70
74
|
\\"type\\": \\"category\\",
|
|
@@ -83,7 +87,7 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
83
87
|
fixtureDir,
|
|
84
88
|
'sidebars-doc-id-not-string.json',
|
|
85
89
|
);
|
|
86
|
-
expect(() =>
|
|
90
|
+
expect(() => loadNormalizedSidebars(sidebarPath, options))
|
|
87
91
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
88
92
|
"{
|
|
89
93
|
\\"type\\": \\"doc\\",
|
|
@@ -101,19 +105,19 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
101
105
|
fixtureDir,
|
|
102
106
|
'sidebars-first-level-not-category.js',
|
|
103
107
|
);
|
|
104
|
-
const result =
|
|
108
|
+
const result = loadNormalizedSidebars(sidebarPath, options);
|
|
105
109
|
expect(result).toMatchSnapshot();
|
|
106
110
|
});
|
|
107
111
|
|
|
108
112
|
test('sidebars link', async () => {
|
|
109
113
|
const sidebarPath = path.join(fixtureDir, 'sidebars-link.json');
|
|
110
|
-
const result =
|
|
114
|
+
const result = loadNormalizedSidebars(sidebarPath, options);
|
|
111
115
|
expect(result).toMatchSnapshot();
|
|
112
116
|
});
|
|
113
117
|
|
|
114
118
|
test('sidebars link wrong label', async () => {
|
|
115
119
|
const sidebarPath = path.join(fixtureDir, 'sidebars-link-wrong-label.json');
|
|
116
|
-
expect(() =>
|
|
120
|
+
expect(() => loadNormalizedSidebars(sidebarPath, options))
|
|
117
121
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
118
122
|
"{
|
|
119
123
|
\\"type\\": \\"link\\",
|
|
@@ -127,7 +131,7 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
127
131
|
|
|
128
132
|
test('sidebars link wrong href', async () => {
|
|
129
133
|
const sidebarPath = path.join(fixtureDir, 'sidebars-link-wrong-href.json');
|
|
130
|
-
expect(() =>
|
|
134
|
+
expect(() => loadNormalizedSidebars(sidebarPath, options))
|
|
131
135
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
132
136
|
"{
|
|
133
137
|
\\"type\\": \\"link\\",
|
|
@@ -143,7 +147,7 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
143
147
|
|
|
144
148
|
test('sidebars with unknown sidebar item type', async () => {
|
|
145
149
|
const sidebarPath = path.join(fixtureDir, 'sidebars-unknown-type.json');
|
|
146
|
-
expect(() =>
|
|
150
|
+
expect(() => loadNormalizedSidebars(sidebarPath, options))
|
|
147
151
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
148
152
|
"{
|
|
149
153
|
\\"type\\": \\"superman\\",
|
|
@@ -156,7 +160,7 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
156
160
|
|
|
157
161
|
test('sidebars with known sidebar item type but wrong field', async () => {
|
|
158
162
|
const sidebarPath = path.join(fixtureDir, 'sidebars-wrong-field.json');
|
|
159
|
-
expect(() =>
|
|
163
|
+
expect(() => loadNormalizedSidebars(sidebarPath, options))
|
|
160
164
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
161
165
|
"{
|
|
162
166
|
\\"type\\": \\"category\\",
|
|
@@ -170,24 +174,22 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
170
174
|
});
|
|
171
175
|
|
|
172
176
|
test('unexisting path', () => {
|
|
173
|
-
expect(
|
|
177
|
+
expect(loadNormalizedSidebars('badpath', options)).toEqual(
|
|
174
178
|
DisabledSidebars,
|
|
175
179
|
);
|
|
176
180
|
});
|
|
177
181
|
|
|
178
182
|
test('undefined path', () => {
|
|
179
|
-
expect(
|
|
180
|
-
DefaultSidebars,
|
|
181
|
-
);
|
|
183
|
+
expect(loadNormalizedSidebars(undefined, options)).toEqual(DefaultSidebars);
|
|
182
184
|
});
|
|
183
185
|
|
|
184
186
|
test('literal false path', () => {
|
|
185
|
-
expect(
|
|
187
|
+
expect(loadNormalizedSidebars(false, options)).toEqual(DisabledSidebars);
|
|
186
188
|
});
|
|
187
189
|
|
|
188
190
|
test('sidebars with category.collapsed property', async () => {
|
|
189
191
|
const sidebarPath = path.join(fixtureDir, 'sidebars-collapsed.json');
|
|
190
|
-
const result =
|
|
192
|
+
const result = loadNormalizedSidebars(sidebarPath, options);
|
|
191
193
|
expect(result).toMatchSnapshot();
|
|
192
194
|
});
|
|
193
195
|
|
|
@@ -196,7 +198,7 @@ describe('loadUnprocessedSidebars', () => {
|
|
|
196
198
|
fixtureDir,
|
|
197
199
|
'sidebars-collapsed-first-level.json',
|
|
198
200
|
);
|
|
199
|
-
const result =
|
|
201
|
+
const result = loadNormalizedSidebars(sidebarPath, options);
|
|
200
202
|
expect(result).toMatchSnapshot();
|
|
201
203
|
});
|
|
202
204
|
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {processSidebars} from '../processor';
|
|
8
|
+
import {processSidebars, SidebarProcessorParams} from '../processor';
|
|
9
9
|
import type {
|
|
10
10
|
SidebarItem,
|
|
11
11
|
SidebarItemsGenerator,
|
|
@@ -13,23 +13,50 @@ import type {
|
|
|
13
13
|
NormalizedSidebars,
|
|
14
14
|
} from '../types';
|
|
15
15
|
import {DefaultSidebarItemsGenerator} from '../generator';
|
|
16
|
+
import {createSlugger} from '@docusaurus/utils';
|
|
17
|
+
import {VersionMetadata} from '../../types';
|
|
18
|
+
import {DefaultNumberPrefixParser} from '../../numberPrefix';
|
|
16
19
|
|
|
17
20
|
describe('processSidebars', () => {
|
|
21
|
+
function createStaticSidebarItemGenerator(
|
|
22
|
+
sidebarSlice: SidebarItem[],
|
|
23
|
+
): SidebarItemsGenerator {
|
|
24
|
+
return jest.fn(async () => sidebarSlice);
|
|
25
|
+
}
|
|
26
|
+
|
|
18
27
|
const StaticGeneratedSidebarSlice: SidebarItem[] = [
|
|
19
28
|
{type: 'doc', id: 'doc-generated-id-1'},
|
|
20
29
|
{type: 'doc', id: 'doc-generated-id-2'},
|
|
21
30
|
];
|
|
22
31
|
|
|
23
|
-
const StaticSidebarItemsGenerator: SidebarItemsGenerator =
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
const StaticSidebarItemsGenerator: SidebarItemsGenerator =
|
|
33
|
+
createStaticSidebarItemGenerator(StaticGeneratedSidebarSlice);
|
|
34
|
+
|
|
35
|
+
// @ts-expect-error: good enough for this test
|
|
36
|
+
const version: VersionMetadata = {
|
|
37
|
+
versionName: '1.0.0',
|
|
38
|
+
versionPath: '/docs/1.0.0',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const params: SidebarProcessorParams = {
|
|
42
|
+
sidebarItemsGenerator: StaticSidebarItemsGenerator,
|
|
43
|
+
docs: [],
|
|
44
|
+
version,
|
|
45
|
+
numberPrefixParser: DefaultNumberPrefixParser,
|
|
46
|
+
categoryLabelSlugger: createSlugger(),
|
|
47
|
+
sidebarOptions: {
|
|
48
|
+
sidebarCollapsed: true,
|
|
49
|
+
sidebarCollapsible: true,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
26
52
|
|
|
27
|
-
async function testProcessSidebars(
|
|
53
|
+
async function testProcessSidebars(
|
|
54
|
+
unprocessedSidebars: NormalizedSidebars,
|
|
55
|
+
paramsOverrides: Partial<SidebarProcessorParams> = {},
|
|
56
|
+
) {
|
|
28
57
|
return processSidebars(unprocessedSidebars, {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// @ts-expect-error: useless for this test
|
|
32
|
-
version: {},
|
|
58
|
+
...params,
|
|
59
|
+
...paramsOverrides,
|
|
33
60
|
});
|
|
34
61
|
}
|
|
35
62
|
|
|
@@ -69,13 +96,18 @@ describe('processSidebars', () => {
|
|
|
69
96
|
{type: 'doc', id: 'doc1'},
|
|
70
97
|
{
|
|
71
98
|
type: 'category',
|
|
99
|
+
label: 'Category',
|
|
100
|
+
link: {
|
|
101
|
+
type: 'generated-index',
|
|
102
|
+
slug: 'category-generated-index-slug',
|
|
103
|
+
permalink: 'category-generated-index-permalink',
|
|
104
|
+
},
|
|
72
105
|
collapsed: false,
|
|
73
106
|
collapsible: true,
|
|
74
107
|
items: [
|
|
75
108
|
{type: 'doc', id: 'doc2'},
|
|
76
109
|
{type: 'autogenerated', dirName: 'dir1'},
|
|
77
110
|
],
|
|
78
|
-
label: 'Category',
|
|
79
111
|
},
|
|
80
112
|
{type: 'link', href: 'https://facebook.com', label: 'FB'},
|
|
81
113
|
],
|
|
@@ -86,10 +118,10 @@ describe('processSidebars', () => {
|
|
|
86
118
|
{type: 'autogenerated', dirName: 'dir3'},
|
|
87
119
|
{
|
|
88
120
|
type: 'category',
|
|
121
|
+
label: 'Category',
|
|
89
122
|
collapsed: false,
|
|
90
123
|
collapsible: true,
|
|
91
124
|
items: [{type: 'doc', id: 'doc4'}],
|
|
92
|
-
label: 'Category',
|
|
93
125
|
},
|
|
94
126
|
],
|
|
95
127
|
};
|
|
@@ -100,20 +132,32 @@ describe('processSidebars', () => {
|
|
|
100
132
|
expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
|
|
101
133
|
defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
|
102
134
|
item: {type: 'autogenerated', dirName: 'dir1'},
|
|
103
|
-
docs:
|
|
104
|
-
version: {
|
|
135
|
+
docs: params.docs,
|
|
136
|
+
version: {
|
|
137
|
+
versionName: version.versionName,
|
|
138
|
+
},
|
|
139
|
+
numberPrefixParser: DefaultNumberPrefixParser,
|
|
140
|
+
options: params.sidebarOptions,
|
|
105
141
|
});
|
|
106
142
|
expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
|
|
107
143
|
defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
|
108
144
|
item: {type: 'autogenerated', dirName: 'dir2'},
|
|
109
|
-
docs:
|
|
110
|
-
version: {
|
|
145
|
+
docs: params.docs,
|
|
146
|
+
version: {
|
|
147
|
+
versionName: version.versionName,
|
|
148
|
+
},
|
|
149
|
+
numberPrefixParser: DefaultNumberPrefixParser,
|
|
150
|
+
options: params.sidebarOptions,
|
|
111
151
|
});
|
|
112
152
|
expect(StaticSidebarItemsGenerator).toHaveBeenCalledWith({
|
|
113
153
|
defaultSidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
|
114
154
|
item: {type: 'autogenerated', dirName: 'dir3'},
|
|
115
|
-
docs:
|
|
116
|
-
version: {
|
|
155
|
+
docs: params.docs,
|
|
156
|
+
version: {
|
|
157
|
+
versionName: version.versionName,
|
|
158
|
+
},
|
|
159
|
+
numberPrefixParser: DefaultNumberPrefixParser,
|
|
160
|
+
options: params.sidebarOptions,
|
|
117
161
|
});
|
|
118
162
|
|
|
119
163
|
expect(processedSidebar).toEqual({
|
|
@@ -121,10 +165,15 @@ describe('processSidebars', () => {
|
|
|
121
165
|
{type: 'doc', id: 'doc1'},
|
|
122
166
|
{
|
|
123
167
|
type: 'category',
|
|
168
|
+
label: 'Category',
|
|
169
|
+
link: {
|
|
170
|
+
type: 'generated-index',
|
|
171
|
+
slug: 'category-generated-index-slug',
|
|
172
|
+
permalink: 'category-generated-index-permalink',
|
|
173
|
+
},
|
|
124
174
|
collapsed: false,
|
|
125
175
|
collapsible: true,
|
|
126
176
|
items: [{type: 'doc', id: 'doc2'}, ...StaticGeneratedSidebarSlice],
|
|
127
|
-
label: 'Category',
|
|
128
177
|
},
|
|
129
178
|
{type: 'link', href: 'https://facebook.com', label: 'FB'},
|
|
130
179
|
],
|
|
@@ -135,10 +184,52 @@ describe('processSidebars', () => {
|
|
|
135
184
|
...StaticGeneratedSidebarSlice,
|
|
136
185
|
{
|
|
137
186
|
type: 'category',
|
|
187
|
+
label: 'Category',
|
|
138
188
|
collapsed: false,
|
|
139
189
|
collapsible: true,
|
|
140
190
|
items: [{type: 'doc', id: 'doc4'}],
|
|
141
|
-
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
} as Sidebars);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
test('ensure generated items are normalized', async () => {
|
|
197
|
+
const sidebarSliceContainingCategoryGeneratedIndex: SidebarItem[] = [
|
|
198
|
+
{
|
|
199
|
+
type: 'category',
|
|
200
|
+
label: 'Generated category',
|
|
201
|
+
link: {
|
|
202
|
+
type: 'generated-index',
|
|
203
|
+
slug: 'generated-cat-index-slug',
|
|
204
|
+
// @ts-expect-error: TODO undefined should be allowed here, typing error needing refactor
|
|
205
|
+
permalink: undefined,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
|
|
210
|
+
const unprocessedSidebars: NormalizedSidebars = {
|
|
211
|
+
someSidebar: [{type: 'autogenerated', dirName: 'dir2'}],
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const processedSidebar = await testProcessSidebars(unprocessedSidebars, {
|
|
215
|
+
sidebarItemsGenerator: createStaticSidebarItemGenerator(
|
|
216
|
+
sidebarSliceContainingCategoryGeneratedIndex,
|
|
217
|
+
),
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
expect(processedSidebar).toEqual({
|
|
221
|
+
someSidebar: [
|
|
222
|
+
{
|
|
223
|
+
type: 'category',
|
|
224
|
+
label: 'Generated category',
|
|
225
|
+
link: {
|
|
226
|
+
type: 'generated-index',
|
|
227
|
+
slug: 'generated-cat-index-slug',
|
|
228
|
+
permalink: '/docs/1.0.0/generated-cat-index-slug',
|
|
229
|
+
},
|
|
230
|
+
items: [],
|
|
231
|
+
collapsible: true,
|
|
232
|
+
collapsed: true,
|
|
142
233
|
},
|
|
143
234
|
],
|
|
144
235
|
} as Sidebars);
|