-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsidebars.adapter.mjs
47 lines (42 loc) · 1.07 KB
/
sidebars.adapter.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const walk = (itemOrItems, callback) => {
if (Array.isArray(itemOrItems)) {
itemOrItems.forEach((item) => {
walk(item, callback)
})
} else {
callback(itemOrItems)
if ('items' in itemOrItems && Array.isArray(itemOrItems.items)) {
walk(itemOrItems.items, callback)
}
}
}
export const officialNextJsDocsSidebarItemsAdapter = (items) => {
const reduced = items.reduce((prev, current) => {
//index.mdは先頭に
if (current.id === 'index') {
return [current, ...prev]
}
//Pages Routerは利用しない
if (current.link?.id === 'pages/index') {
return [...prev]
}
return [...prev, current]
}, [])
walk(reduced, (item) => {
//各カテゴリのトップは折り畳み不可に
if (
[
'index',
'app/index',
'app/getting-started/index',
'app/building-your-application/index',
'app/api-reference/index',
'architecture/index',
'community/index',
].includes(item?.link?.id)
) {
item.collapsible = false
}
})
return reduced
}