Skip to content

Commit

Permalink
hotfix-gitbook
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Aug 15, 2023
1 parent cad975f commit 454c85f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions themes/gitbook/components/NavPostList.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ const NavPostList = (props) => {
const groupedArray = filteredNavPages?.reduce((groups, item) => {
const categoryName = item?.category ? item?.category : '' // 将category转换为字符串

let existingGroup = null
// 开启自动分组排序
if (JSON.parse(CONFIG.AUTO_SORT)) {
const existingGroup = groups.find(group => group.category === categoryName)
if (existingGroup) {
existingGroup.items.push(item)
} else {
groups.push({ category: categoryName, items: [item] })
}
existingGroup = groups.find(group => group.category === categoryName) // 搜索同名的最后一个分组
} else {
const lastGroup = groups[groups.length - 1] // 获取最后一个分组
if (!lastGroup || lastGroup?.category !== categoryName) { // 如果当前元素的category与上一个元素不同,则创建新分组
groups.push({ category: categoryName, items: [] })
}
existingGroup = groups[groups.length - 1] // 获取最后一个分组
}

// 添加数据
if (existingGroup && existingGroup.category === categoryName) {
existingGroup.items.push(item)
} else {
groups.push({ category: categoryName, items: [item] })
}
return groups
}, [])
Expand Down

0 comments on commit 454c85f

Please sign in to comment.