Skip to content

Commit 454c85f

Browse files
committed
hotfix-gitbook
1 parent cad975f commit 454c85f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

themes/gitbook/components/NavPostList.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ const NavPostList = (props) => {
1717
const groupedArray = filteredNavPages?.reduce((groups, item) => {
1818
const categoryName = item?.category ? item?.category : '' // 将category转换为字符串
1919

20+
let existingGroup = null
2021
// 开启自动分组排序
2122
if (JSON.parse(CONFIG.AUTO_SORT)) {
22-
const existingGroup = groups.find(group => group.category === categoryName)
23-
if (existingGroup) {
24-
existingGroup.items.push(item)
25-
} else {
26-
groups.push({ category: categoryName, items: [item] })
27-
}
23+
existingGroup = groups.find(group => group.category === categoryName) // 搜索同名的最后一个分组
2824
} else {
29-
const lastGroup = groups[groups.length - 1] // 获取最后一个分组
30-
if (!lastGroup || lastGroup?.category !== categoryName) { // 如果当前元素的category与上一个元素不同,则创建新分组
31-
groups.push({ category: categoryName, items: [] })
32-
}
25+
existingGroup = groups[groups.length - 1] // 获取最后一个分组
26+
}
27+
28+
// 添加数据
29+
if (existingGroup && existingGroup.category === categoryName) {
30+
existingGroup.items.push(item)
31+
} else {
32+
groups.push({ category: categoryName, items: [item] })
3333
}
3434
return groups
3535
}, [])

0 commit comments

Comments
 (0)