@aravindc26/velu 0.10.0 → 0.11.0
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/package.json +1 -1
- package/schema/velu.schema.json +714 -16
- package/src/build.ts +207 -43
- package/src/cli.ts +65 -2
- package/src/engine/_server.mjs +127 -18
- package/src/engine/app/(docs)/[[...slug]]/layout.tsx +87 -0
- package/src/engine/app/(docs)/[[...slug]]/page.tsx +83 -6
- package/src/engine/app/(docs)/layout.tsx +1 -13
- package/src/engine/app/global.css +327 -0
- package/src/engine/app/layout.tsx +3 -7
- package/src/engine/app/search.css +20 -0
- package/src/engine/components/lang-switcher.tsx +95 -0
- package/src/engine/components/product-switcher.tsx +78 -0
- package/src/engine/components/providers.tsx +26 -0
- package/src/engine/components/search.tsx +66 -3
- package/src/engine/components/sidebar-links.tsx +51 -0
- package/src/engine/components/theme-toggle.tsx +39 -0
- package/src/engine/components/version-switcher.tsx +89 -0
- package/src/engine/lib/layout.shared.ts +28 -6
- package/src/engine/lib/navigation-normalize.mjs +456 -0
- package/src/engine/lib/navigation-normalize.ts +488 -0
- package/src/engine/lib/source.ts +14 -0
- package/src/engine/lib/velu.ts +267 -3
- package/src/engine/next.config.mjs +2 -2
- package/src/engine/src/lib/velu.ts +86 -13
- package/src/navigation-normalize.ts +488 -0
- package/src/validate.ts +116 -18
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
function isObject(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function isSeparator(value) {
|
|
6
|
+
return isObject(value) && typeof value.separator === 'string';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function isLink(value) {
|
|
10
|
+
return isObject(value) && typeof value.href === 'string' && typeof value.label === 'string';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isGroupLike(value) {
|
|
14
|
+
return isObject(value) && typeof value.group === 'string';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isMenuItem(value) {
|
|
18
|
+
return isObject(value) && typeof value.item === 'string';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isTabLike(value) {
|
|
22
|
+
return isObject(value) && typeof value.tab === 'string';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isAnchorLike(value) {
|
|
26
|
+
return isObject(value) && typeof value.anchor === 'string';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isDropdownLike(value) {
|
|
30
|
+
return isObject(value) && typeof value.dropdown === 'string';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function isGroupEntry(value) {
|
|
34
|
+
return typeof value === 'object' && value !== null && 'group' in value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function slugify(input, fallback) {
|
|
38
|
+
const slug = String(input)
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.trim()
|
|
41
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
42
|
+
.replace(/^-+|-+$/g, '');
|
|
43
|
+
return slug || fallback;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function uniqueSlug(base, used) {
|
|
47
|
+
if (!used.has(base)) {
|
|
48
|
+
used.add(base);
|
|
49
|
+
return base;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let count = 2;
|
|
53
|
+
while (used.has(`${base}-${count}`)) count += 1;
|
|
54
|
+
|
|
55
|
+
const candidate = `${base}-${count}`;
|
|
56
|
+
used.add(candidate);
|
|
57
|
+
return candidate;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
function normalizeLink(value) {
|
|
62
|
+
const out = { href: value.href, label: value.label };
|
|
63
|
+
if (typeof value.icon === 'string' && value.icon.length > 0) out.icon = value.icon;
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function normalizeAnchorLink(value) {
|
|
68
|
+
const href = typeof value.href === 'string' ? value.href : '#';
|
|
69
|
+
const label = typeof value.anchor === 'string' ? value.anchor : 'Link';
|
|
70
|
+
const icon = typeof value.icon === 'string' ? value.icon : undefined;
|
|
71
|
+
return icon ? { href, label, icon } : { href, label };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function hasContent(value) {
|
|
75
|
+
const hasSimple =
|
|
76
|
+
(Array.isArray(value.pages) && value.pages.length > 0) ||
|
|
77
|
+
(Array.isArray(value.groups) && value.groups.length > 0) ||
|
|
78
|
+
(Array.isArray(value.menu) && value.menu.length > 0) ||
|
|
79
|
+
(Array.isArray(value.tabs) && value.tabs.length > 0) ||
|
|
80
|
+
(Array.isArray(value.dropdowns) && value.dropdowns.length > 0);
|
|
81
|
+
|
|
82
|
+
const hasAnchors =
|
|
83
|
+
Array.isArray(value.anchors) &&
|
|
84
|
+
value.anchors.some(
|
|
85
|
+
(a) =>
|
|
86
|
+
isAnchorLike(a) &&
|
|
87
|
+
((Array.isArray(a.tabs) && a.tabs.length > 0) ||
|
|
88
|
+
(Array.isArray(a.groups) && a.groups.length > 0) ||
|
|
89
|
+
(Array.isArray(a.pages) && a.pages.length > 0) ||
|
|
90
|
+
(Array.isArray(a.menu) && a.menu.length > 0) ||
|
|
91
|
+
(Array.isArray(a.anchors) && a.anchors.length > 0) ||
|
|
92
|
+
(Array.isArray(a.dropdowns) && a.dropdowns.length > 0))
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return hasSimple || hasAnchors;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function normalizeGroup(rawGroup, usedGroupSlugs) {
|
|
99
|
+
const groupName = typeof rawGroup.group === 'string' ? rawGroup.group : 'Group';
|
|
100
|
+
const rawSlug = typeof rawGroup.slug === 'string' ? rawGroup.slug : groupName;
|
|
101
|
+
const groupSlug = uniqueSlug(slugify(rawSlug, 'group'), usedGroupSlugs);
|
|
102
|
+
|
|
103
|
+
const childUsedSlugs = new Set();
|
|
104
|
+
const pages = collectEntries(rawGroup, childUsedSlugs);
|
|
105
|
+
|
|
106
|
+
const out = { group: groupName, slug: groupSlug, pages };
|
|
107
|
+
if (typeof rawGroup.icon === 'string') out.icon = rawGroup.icon;
|
|
108
|
+
if (typeof rawGroup.tag === 'string') out.tag = rawGroup.tag;
|
|
109
|
+
if (typeof rawGroup.expanded === 'boolean') out.expanded = rawGroup.expanded;
|
|
110
|
+
if (typeof rawGroup.description === 'string') out.description = rawGroup.description;
|
|
111
|
+
if (typeof rawGroup.hidden === 'boolean') out.hidden = rawGroup.hidden;
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function normalizeMenuItem(rawItem, usedGroupSlugs) {
|
|
116
|
+
const name = typeof rawItem.item === 'string' ? rawItem.item : 'Menu';
|
|
117
|
+
const rawSlug = typeof rawItem.slug === 'string' ? rawItem.slug : name;
|
|
118
|
+
const slug = uniqueSlug(slugify(rawSlug, 'menu'), usedGroupSlugs);
|
|
119
|
+
|
|
120
|
+
const nestedGroupSlugs = new Set();
|
|
121
|
+
const pages = collectEntries(rawItem, nestedGroupSlugs);
|
|
122
|
+
const out = { group: name, slug, pages };
|
|
123
|
+
if (typeof rawItem.icon === 'string') out.icon = rawItem.icon;
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function normalizeTabAsGroup(rawTab, usedGroupSlugs) {
|
|
128
|
+
const tabName = typeof rawTab.tab === 'string' ? rawTab.tab : 'Tab';
|
|
129
|
+
const rawSlug = typeof rawTab.slug === 'string' ? rawTab.slug : tabName;
|
|
130
|
+
const slug = uniqueSlug(slugify(rawSlug, 'tab'), usedGroupSlugs);
|
|
131
|
+
const nestedGroupSlugs = new Set();
|
|
132
|
+
const pages = collectEntries(rawTab, nestedGroupSlugs);
|
|
133
|
+
|
|
134
|
+
if (typeof rawTab.href === 'string' && rawTab.href.length > 0 && !hasContent(rawTab)) {
|
|
135
|
+
pages.push({ href: rawTab.href, label: tabName, ...(typeof rawTab.icon === 'string' ? { icon: rawTab.icon } : {}) });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const out = { group: tabName, slug, pages };
|
|
139
|
+
if (typeof rawTab.icon === 'string') out.icon = rawTab.icon;
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function normalizeDropdownAsGroup(rawDropdown, usedGroupSlugs) {
|
|
144
|
+
return normalizeTabAsGroup(
|
|
145
|
+
{
|
|
146
|
+
tab: rawDropdown.dropdown,
|
|
147
|
+
slug: rawDropdown.slug,
|
|
148
|
+
icon: rawDropdown.icon,
|
|
149
|
+
href: rawDropdown.href,
|
|
150
|
+
groups: rawDropdown.groups,
|
|
151
|
+
pages: rawDropdown.pages,
|
|
152
|
+
menu: rawDropdown.menu,
|
|
153
|
+
anchors: rawDropdown.anchors,
|
|
154
|
+
dropdowns: rawDropdown.dropdowns,
|
|
155
|
+
tabs: rawDropdown.tabs,
|
|
156
|
+
},
|
|
157
|
+
usedGroupSlugs
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function normalizeAnchorAsGroup(rawAnchor, usedGroupSlugs) {
|
|
162
|
+
const anchorName = typeof rawAnchor.anchor === 'string' ? rawAnchor.anchor : 'Anchor';
|
|
163
|
+
const rawSlug = typeof rawAnchor.slug === 'string' ? rawAnchor.slug : anchorName;
|
|
164
|
+
const slug = uniqueSlug(slugify(rawSlug, 'anchor'), usedGroupSlugs);
|
|
165
|
+
const nestedGroupSlugs = new Set();
|
|
166
|
+
const pages = collectEntries(rawAnchor, nestedGroupSlugs);
|
|
167
|
+
|
|
168
|
+
const out = { group: anchorName, slug, pages };
|
|
169
|
+
if (typeof rawAnchor.icon === 'string') out.icon = rawAnchor.icon;
|
|
170
|
+
return out;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function collectEntries(rawSection, usedGroupSlugs) {
|
|
174
|
+
const entries = [];
|
|
175
|
+
|
|
176
|
+
for (const item of Array.isArray(rawSection.menu) ? rawSection.menu : []) {
|
|
177
|
+
if (isMenuItem(item)) entries.push(normalizeMenuItem(item, usedGroupSlugs));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
for (const group of Array.isArray(rawSection.groups) ? rawSection.groups : []) {
|
|
181
|
+
if (isGroupLike(group)) entries.push(normalizeGroup(group, usedGroupSlugs));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
for (const item of Array.isArray(rawSection.pages) ? rawSection.pages : []) {
|
|
185
|
+
if (typeof item === 'string') entries.push(item);
|
|
186
|
+
else if (isSeparator(item)) entries.push({ separator: item.separator });
|
|
187
|
+
else if (isLink(item)) entries.push(normalizeLink(item));
|
|
188
|
+
else if (isGroupLike(item)) entries.push(normalizeGroup(item, usedGroupSlugs));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
for (const anchor of Array.isArray(rawSection.anchors) ? rawSection.anchors : []) {
|
|
192
|
+
if (!isAnchorLike(anchor)) continue;
|
|
193
|
+
|
|
194
|
+
const hrefOnly = typeof anchor.href === 'string' && anchor.href.length > 0 && !hasContent(anchor);
|
|
195
|
+
if (hrefOnly) entries.push(normalizeAnchorLink(anchor));
|
|
196
|
+
else entries.push(normalizeAnchorAsGroup(anchor, usedGroupSlugs));
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
for (const dropdown of Array.isArray(rawSection.dropdowns) ? rawSection.dropdowns : []) {
|
|
200
|
+
if (isDropdownLike(dropdown)) entries.push(normalizeDropdownAsGroup(dropdown, usedGroupSlugs));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
for (const tab of Array.isArray(rawSection.tabs) ? rawSection.tabs : []) {
|
|
204
|
+
if (isTabLike(tab)) entries.push(normalizeTabAsGroup(tab, usedGroupSlugs));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return entries;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function normalizeTab(rawTab, usedTabSlugs, slugPrefix) {
|
|
211
|
+
const tabName = typeof rawTab.tab === 'string' ? rawTab.tab : 'Tab';
|
|
212
|
+
const rawSlug = typeof rawTab.slug === 'string' ? rawTab.slug : tabName;
|
|
213
|
+
const tabSlugPart = slugify(rawSlug, 'tab');
|
|
214
|
+
const fullSlug = slugPrefix ? `${slugPrefix}/${tabSlugPart}` : tabSlugPart;
|
|
215
|
+
const slug = uniqueSlug(fullSlug, usedTabSlugs);
|
|
216
|
+
|
|
217
|
+
const out = { tab: tabName, slug };
|
|
218
|
+
if (typeof rawTab.icon === 'string') out.icon = rawTab.icon;
|
|
219
|
+
|
|
220
|
+
if (typeof rawTab.href === 'string' && rawTab.href.length > 0 && !hasContent(rawTab)) {
|
|
221
|
+
out.href = rawTab.href;
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const groupSlugSet = new Set();
|
|
226
|
+
const entries = collectEntries(rawTab, groupSlugSet);
|
|
227
|
+
const groups = [];
|
|
228
|
+
const pages = [];
|
|
229
|
+
|
|
230
|
+
for (const entry of entries) {
|
|
231
|
+
if (isGroupEntry(entry)) groups.push(entry);
|
|
232
|
+
else pages.push(entry);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (groups.length > 0) out.groups = groups;
|
|
236
|
+
if (pages.length > 0) out.pages = pages;
|
|
237
|
+
return out;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function normalizeDropdownToTab(rawDropdown, usedTabSlugs, slugPrefix) {
|
|
241
|
+
return normalizeTab(
|
|
242
|
+
{
|
|
243
|
+
tab: rawDropdown.dropdown,
|
|
244
|
+
slug: rawDropdown.slug,
|
|
245
|
+
icon: rawDropdown.icon,
|
|
246
|
+
href: rawDropdown.href,
|
|
247
|
+
groups: rawDropdown.groups,
|
|
248
|
+
pages: rawDropdown.pages,
|
|
249
|
+
menu: rawDropdown.menu,
|
|
250
|
+
anchors: rawDropdown.anchors,
|
|
251
|
+
dropdowns: rawDropdown.dropdowns,
|
|
252
|
+
tabs: rawDropdown.tabs,
|
|
253
|
+
},
|
|
254
|
+
usedTabSlugs,
|
|
255
|
+
slugPrefix
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function normalizeTabList(rawTabs, usedTabSlugs, slugPrefix = '') {
|
|
260
|
+
const tabs = [];
|
|
261
|
+
for (const item of rawTabs) {
|
|
262
|
+
if (isTabLike(item)) tabs.push(normalizeTab(item, usedTabSlugs, slugPrefix));
|
|
263
|
+
}
|
|
264
|
+
return tabs;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function normalizeDropdownList(rawDropdowns, usedTabSlugs, slugPrefix = '') {
|
|
268
|
+
const tabs = [];
|
|
269
|
+
for (const item of rawDropdowns) {
|
|
270
|
+
if (isDropdownLike(item)) tabs.push(normalizeDropdownToTab(item, usedTabSlugs, slugPrefix));
|
|
271
|
+
}
|
|
272
|
+
return tabs;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function normalizeNavigationTabs(navigation, usedTabSlugs = new Set()) {
|
|
276
|
+
if (!isObject(navigation)) return [];
|
|
277
|
+
|
|
278
|
+
const tabs = [];
|
|
279
|
+
|
|
280
|
+
tabs.push(...normalizeTabList(Array.isArray(navigation.tabs) ? navigation.tabs : [], usedTabSlugs));
|
|
281
|
+
tabs.push(...normalizeDropdownList(Array.isArray(navigation.dropdowns) ? navigation.dropdowns : [], usedTabSlugs));
|
|
282
|
+
|
|
283
|
+
if (Array.isArray(navigation.products)) {
|
|
284
|
+
navigation.products.forEach((product, index) => {
|
|
285
|
+
if (!isObject(product)) return;
|
|
286
|
+
const productName = typeof product.product === 'string' ? product.product : `Product ${index + 1}`;
|
|
287
|
+
const prefix = slugify(productName, `product-${index + 1}`);
|
|
288
|
+
|
|
289
|
+
tabs.push(...normalizeTabList(Array.isArray(product.tabs) ? product.tabs : [], usedTabSlugs, prefix));
|
|
290
|
+
tabs.push(...normalizeDropdownList(Array.isArray(product.dropdowns) ? product.dropdowns : [], usedTabSlugs, prefix));
|
|
291
|
+
|
|
292
|
+
if (!Array.isArray(product.tabs) && !Array.isArray(product.dropdowns)) {
|
|
293
|
+
if (hasContent(product)) {
|
|
294
|
+
tabs.push(
|
|
295
|
+
normalizeTab(
|
|
296
|
+
{
|
|
297
|
+
tab: productName,
|
|
298
|
+
slug: prefix,
|
|
299
|
+
icon: product.icon,
|
|
300
|
+
groups: product.groups,
|
|
301
|
+
pages: product.pages,
|
|
302
|
+
menu: product.menu,
|
|
303
|
+
anchors: product.anchors,
|
|
304
|
+
dropdowns: product.dropdowns,
|
|
305
|
+
tabs: product.tabs,
|
|
306
|
+
},
|
|
307
|
+
usedTabSlugs,
|
|
308
|
+
''
|
|
309
|
+
)
|
|
310
|
+
);
|
|
311
|
+
} else if (typeof product.href === 'string' && product.href.length > 0) {
|
|
312
|
+
tabs.push(
|
|
313
|
+
normalizeTab(
|
|
314
|
+
{
|
|
315
|
+
tab: productName,
|
|
316
|
+
slug: prefix,
|
|
317
|
+
icon: product.icon,
|
|
318
|
+
href: product.href,
|
|
319
|
+
},
|
|
320
|
+
usedTabSlugs,
|
|
321
|
+
''
|
|
322
|
+
)
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
if (Array.isArray(navigation.versions)) {
|
|
330
|
+
navigation.versions.forEach((version, index) => {
|
|
331
|
+
if (!isObject(version)) return;
|
|
332
|
+
const versionName = typeof version.version === 'string' ? version.version : `Version ${index + 1}`;
|
|
333
|
+
const prefix = slugify(versionName, `version-${index + 1}`);
|
|
334
|
+
|
|
335
|
+
tabs.push(...normalizeTabList(Array.isArray(version.tabs) ? version.tabs : [], usedTabSlugs, prefix));
|
|
336
|
+
tabs.push(...normalizeDropdownList(Array.isArray(version.dropdowns) ? version.dropdowns : [], usedTabSlugs, prefix));
|
|
337
|
+
|
|
338
|
+
if (!Array.isArray(version.tabs) && !Array.isArray(version.dropdowns)) {
|
|
339
|
+
if (hasContent(version)) {
|
|
340
|
+
tabs.push(
|
|
341
|
+
normalizeTab(
|
|
342
|
+
{
|
|
343
|
+
tab: versionName,
|
|
344
|
+
slug: prefix,
|
|
345
|
+
groups: version.groups,
|
|
346
|
+
pages: version.pages,
|
|
347
|
+
menu: version.menu,
|
|
348
|
+
anchors: version.anchors,
|
|
349
|
+
dropdowns: version.dropdowns,
|
|
350
|
+
tabs: version.tabs,
|
|
351
|
+
},
|
|
352
|
+
usedTabSlugs,
|
|
353
|
+
''
|
|
354
|
+
)
|
|
355
|
+
);
|
|
356
|
+
} else if (typeof version.href === 'string' && version.href.length > 0) {
|
|
357
|
+
tabs.push(
|
|
358
|
+
normalizeTab(
|
|
359
|
+
{
|
|
360
|
+
tab: versionName,
|
|
361
|
+
slug: prefix,
|
|
362
|
+
href: version.href,
|
|
363
|
+
},
|
|
364
|
+
usedTabSlugs,
|
|
365
|
+
''
|
|
366
|
+
)
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
if (Array.isArray(navigation.anchors)) {
|
|
374
|
+
navigation.anchors.forEach((anchor, index) => {
|
|
375
|
+
if (!isAnchorLike(anchor)) return;
|
|
376
|
+
|
|
377
|
+
const anchorName = typeof anchor.anchor === 'string' ? anchor.anchor : `Anchor ${index + 1}`;
|
|
378
|
+
const prefix = slugify(anchorName, `anchor-${index + 1}`);
|
|
379
|
+
|
|
380
|
+
if (Array.isArray(anchor.tabs)) {
|
|
381
|
+
tabs.push(...normalizeTabList(anchor.tabs, usedTabSlugs, prefix));
|
|
382
|
+
} else if (hasContent(anchor)) {
|
|
383
|
+
tabs.push(
|
|
384
|
+
normalizeTab(
|
|
385
|
+
{
|
|
386
|
+
tab: anchorName,
|
|
387
|
+
slug: prefix,
|
|
388
|
+
icon: anchor.icon,
|
|
389
|
+
groups: anchor.groups,
|
|
390
|
+
pages: anchor.pages,
|
|
391
|
+
menu: anchor.menu,
|
|
392
|
+
anchors: anchor.anchors,
|
|
393
|
+
dropdowns: anchor.dropdowns,
|
|
394
|
+
tabs: anchor.tabs,
|
|
395
|
+
},
|
|
396
|
+
usedTabSlugs,
|
|
397
|
+
''
|
|
398
|
+
)
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const hasRootGroups = Array.isArray(navigation.groups) && navigation.groups.length > 0;
|
|
405
|
+
const hasRootPages = Array.isArray(navigation.pages) && navigation.pages.length > 0;
|
|
406
|
+
const hasRootMenu = Array.isArray(navigation.menu) && navigation.menu.length > 0;
|
|
407
|
+
|
|
408
|
+
if (tabs.length === 0 && (hasRootGroups || hasRootPages || hasRootMenu)) {
|
|
409
|
+
tabs.push(
|
|
410
|
+
normalizeTab(
|
|
411
|
+
{
|
|
412
|
+
tab: 'Documentation',
|
|
413
|
+
slug: 'documentation',
|
|
414
|
+
groups: navigation.groups,
|
|
415
|
+
pages: navigation.pages,
|
|
416
|
+
menu: navigation.menu,
|
|
417
|
+
anchors: navigation.anchors,
|
|
418
|
+
dropdowns: navigation.dropdowns,
|
|
419
|
+
tabs: navigation.tabs,
|
|
420
|
+
},
|
|
421
|
+
usedTabSlugs,
|
|
422
|
+
''
|
|
423
|
+
)
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return tabs;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function normalizeLanguageEntries(languages) {
|
|
431
|
+
if (!Array.isArray(languages)) return [];
|
|
432
|
+
|
|
433
|
+
return languages
|
|
434
|
+
.filter((entry) => isObject(entry))
|
|
435
|
+
.map((entry) => {
|
|
436
|
+
const usedTabSlugs = new Set();
|
|
437
|
+
return {
|
|
438
|
+
...entry,
|
|
439
|
+
tabs: normalizeNavigationTabs(entry, usedTabSlugs),
|
|
440
|
+
};
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export function normalizeConfigNavigation(config) {
|
|
445
|
+
const nav = isObject(config?.navigation) ? config.navigation : {};
|
|
446
|
+
return {
|
|
447
|
+
...config,
|
|
448
|
+
navigation: {
|
|
449
|
+
...nav,
|
|
450
|
+
tabs: normalizeNavigationTabs(nav),
|
|
451
|
+
languages: normalizeLanguageEntries(nav.languages),
|
|
452
|
+
products: Array.isArray(nav.products) ? nav.products : [],
|
|
453
|
+
versions: Array.isArray(nav.versions) ? nav.versions : [],
|
|
454
|
+
},
|
|
455
|
+
};
|
|
456
|
+
}
|