File tree 1 file changed +10
-10
lines changed
themes/gitbook/components
1 file changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -17,19 +17,19 @@ const NavPostList = (props) => {
17
17
const groupedArray = filteredNavPages ?. reduce ( ( groups , item ) => {
18
18
const categoryName = item ?. category ? item ?. category : '' // 将category转换为字符串
19
19
20
+ let existingGroup = null
20
21
// 开启自动分组排序
21
22
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 ) // 搜索同名的最后一个分组
28
24
} 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 ] } )
33
33
}
34
34
return groups
35
35
} , [ ] )
You can’t perform that action at this time.
0 commit comments