Skip to content

Commit

Permalink
Fix api sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
luooooob committed Oct 17, 2023
1 parent 6590d75 commit 22b9806
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions docs/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ function docsToItems(dirnames) {
const sidebarItemsDocs = docsToItems(['docs'])

function tocToItems(arr) {
if (arr.length > 1 && !arr[0].href) {
return tocToItems([{ ...arr[0], items: arr.slice(1) }])
}
return arr.map(obj => {
const [head, tail] = arr.reduce(([head, tail], x) => {
if (!x.href) {
return [[...head, tail], x]
}
if (tail.name) {
return [head, { ...tail, items: [...(tail.items || []), x] }]
}
return [[...head, x], {}]
}, [[], {}])

const foldArr = [...head, tail]

return foldArr.map(obj => {
let item = {
text: obj.name,
}
Expand All @@ -56,6 +65,8 @@ try {

const sidebarItemsApi = tocToItems(apiObj)

console.log(JSON.stringify(sidebarItemsApi))

function findFirst(items) {
if (items.length > 0) {
if (items[0].link) {
Expand Down

0 comments on commit 22b9806

Please sign in to comment.