mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-24 23:16:52 +00:00
gitbook 侧边栏支持自动分组自动排序
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import NavPostListEmpty from './NavPostListEmpty'
|
import NavPostListEmpty from './NavPostListEmpty'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import NavPostItem from './NavPostItem'
|
import NavPostItem from './NavPostItem'
|
||||||
|
import CONFIG from '../config'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 博客列表滚动分页
|
* 博客列表滚动分页
|
||||||
@@ -15,10 +16,20 @@ const NavPostList = (props) => {
|
|||||||
let selectedSth = false
|
let selectedSth = false
|
||||||
const groupedArray = filteredNavPages?.reduce((groups, item) => {
|
const groupedArray = filteredNavPages?.reduce((groups, item) => {
|
||||||
const categoryName = item?.category ? item?.category : '' // 将category转换为字符串
|
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) // 将元素加入对应的分组
|
groups[groups.length - 1].items.push(item) // 将元素加入对应的分组
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ const CONFIG = {
|
|||||||
|
|
||||||
INDEX_PAGE: 'about', // 文档首页显示的文章,请确此路径包含在您的notion数据库中
|
INDEX_PAGE: 'about', // 文档首页显示的文章,请确此路径包含在您的notion数据库中
|
||||||
|
|
||||||
|
AUTO_SORT: process.env.NEXT_PUBLIC_GITBOOK_AUTO_SORT || true, // 是否自动按分类名 归组排序文章;自动归组可能会打乱您Notion中的文章顺序
|
||||||
|
|
||||||
// 菜单
|
// 菜单
|
||||||
MENU_CATEGORY: true, // 显示分类
|
MENU_CATEGORY: true, // 显示分类
|
||||||
MENU_TAG: true, // 显示标签
|
MENU_TAG: true, // 显示标签
|
||||||
|
|||||||
Reference in New Issue
Block a user