mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-22 07:26:48 +00:00
group-nav-page
This commit is contained in:
@@ -26,6 +26,7 @@ export async function getGlobalNotionData({
|
||||
}) {
|
||||
// 获取Notion数据
|
||||
const notionPageData = deepClone(await getNotionPageData({ pageId, from }))
|
||||
notionPageData.allNavPages = getNavPages({ allPages: notionPageData.allPages })
|
||||
delete notionPageData.block
|
||||
delete notionPageData.schema
|
||||
delete notionPageData.rawMetadata
|
||||
@@ -168,6 +169,37 @@ function getSiteInfo({ collection, block }) {
|
||||
return { title, description, pageCover, icon }
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导航pages
|
||||
* 转为gitbook这类文档主题设计,精减的标题和内容
|
||||
* 导航页面的条件,必须是Posts
|
||||
* @param {*} param0
|
||||
*/
|
||||
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.join('/') : '' // 将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
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公告
|
||||
*/
|
||||
async function getNotice(post) {
|
||||
if (!post) {
|
||||
return null
|
||||
@@ -183,6 +215,7 @@ const EmptyData = (pageId) => {
|
||||
notice: null,
|
||||
siteInfo: getSiteInfo({}),
|
||||
allPages: [{ id: 1, title: `无法获取Notion数据,请检查Notion_ID: \n 当前 ${pageId}`, summary: '访问文档获取帮助→ https://tangly1024.com/article/vercel-deploy-notion-next', status: 'Published', type: 'Post', slug: '13a171332816461db29d50e9f575b00d', date: { start_date: '2023-04-24', lastEditedTime: '2023-04-24', tagItems: [] } }],
|
||||
allNavPages: [],
|
||||
collection: [],
|
||||
collectionQuery: {},
|
||||
collectionId: null,
|
||||
@@ -275,11 +308,13 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
|
||||
// 新的菜单
|
||||
const customMenu = await getCustomMenu({ collectionData })
|
||||
const latestPosts = getLatestPosts({ allPages, from, latestPostCount: 5 })
|
||||
const allNavPages = getNavPages({ allPages })
|
||||
|
||||
return {
|
||||
notice,
|
||||
siteInfo,
|
||||
allPages,
|
||||
allNavPages,
|
||||
collection,
|
||||
collectionQuery,
|
||||
collectionId,
|
||||
|
||||
Reference in New Issue
Block a user