mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-17 15:09:31 +00:00
gitbook 侧边栏支持自动分组自动排序
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import NavPostListEmpty from './NavPostListEmpty'
|
||||
import { useRouter } from 'next/router'
|
||||
import NavPostItem from './NavPostItem'
|
||||
import CONFIG from '../config'
|
||||
|
||||
/**
|
||||
* 博客列表滚动分页
|
||||
@@ -15,10 +16,20 @@ const NavPostList = (props) => {
|
||||
let selectedSth = false
|
||||
const groupedArray = filteredNavPages?.reduce((groups, item) => {
|
||||
const categoryName = item?.category ? item?.category : '' // 将category转换为字符串
|
||||
const lastGroup = groups[groups.length - 1] // 获取最后一个分组
|
||||
|
||||
if (!lastGroup || lastGroup?.category !== categoryName) { // 如果当前元素的category与上一个元素不同,则创建新分组
|
||||
groups.push({ category: categoryName, items: [] })
|
||||
// 开启自动分组排序
|
||||
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] })
|
||||
}
|
||||
} else {
|
||||
const lastGroup = groups[groups.length - 1] // 获取最后一个分组
|
||||
if (!lastGroup || lastGroup?.category !== categoryName) { // 如果当前元素的category与上一个元素不同,则创建新分组
|
||||
groups.push({ category: categoryName, items: [] })
|
||||
}
|
||||
}
|
||||
|
||||
groups[groups.length - 1].items.push(item) // 将元素加入对应的分组
|
||||
|
||||
Reference in New Issue
Block a user