mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-30 07:26:45 +00:00
整理filterNavPages
This commit is contained in:
@@ -174,8 +174,8 @@ function getSiteInfo({ collection, block }) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导航pages
|
||||
* 转为gitbook这类文档主题设计,精减的标题和内容
|
||||
* 获取导航用的精减文章列表
|
||||
* gitbook主题用到,只保留文章的标题分类标签分类信息,精减掉摘要密码日期等数据
|
||||
* 导航页面的条件,必须是Posts
|
||||
* @param {*} param0
|
||||
*/
|
||||
@@ -183,22 +183,8 @@ export function getNavPages({ allPages }) {
|
||||
const allNavPages = allPages.filter(post => {
|
||||
return post && post?.slug && (!post?.slug?.startsWith('http')) && post?.type === 'Post' && post?.status === 'Published'
|
||||
})
|
||||
const result = allNavPages.map(item => ({ id: item.id, title: item.title || '', category: item.category || null, tags: item.tags || null, summary: item.summary || null, slug: item.slug }))
|
||||
|
||||
const groupedArray = result.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: [] })
|
||||
}
|
||||
|
||||
groups[groups.length - 1].items.push(item) // 将元素加入对应的分组
|
||||
|
||||
return groups
|
||||
}, [])
|
||||
|
||||
return groupedArray
|
||||
return allNavPages.map(item => ({ id: item.id, title: item.title || '', pageCover: item.pageCover || '', category: item.category || null, tags: item.tags || null, summary: item.summary || null, slug: item.slug }))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user