mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-21 23:16:48 +00:00
fix: 修复部分文章无法加载的问题,原因是Notion API加载时block上限1000
修复思路是在加载所有文章时,会首先一次性加载数据库中所有block,此时因为上限1000会发生溢出。之后会读取所有page的IDs,然后逐个获取page对应的block。此时如果发现ID查找不到(说明发生了溢出),则再调用API去逐一获取这些溢出了的page。可能这不是最优解。 修改的代码包括: 1. getDataBaseInfoByNotionAPI中添加上述判断逻辑。 2. 修改getPageProperties函数签名,直接传入block对应的value,而不是block数组。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager'
|
||||
import { getPostBlocks } from '@/lib/notion/getPostBlocks'
|
||||
import { getPostBlocks, getSingleBlock } from '@/lib/notion/getPostBlocks'
|
||||
import { idToUuid } from 'notion-utils'
|
||||
import { deepClone } from '../utils'
|
||||
import { getAllCategories } from './getAllCategories'
|
||||
@@ -185,7 +185,17 @@ export function getNavPages({ allPages }) {
|
||||
return post && post?.slug && (!post?.slug?.startsWith('http')) && post?.type === 'Post' && post?.status === 'Published'
|
||||
})
|
||||
|
||||
return allNavPages.map(item => ({ id: item.id, title: item.title || '', pageCoverThumbnail: item.pageCoverThumbnail || '', category: item.category || null, tags: item.tags || null, summary: item.summary || null, slug: item.slug, pageIcon: item.pageIcon || '', lastEditedDate: item.lastEditedDate }))
|
||||
return allNavPages.map(item => ({
|
||||
id: item.id,
|
||||
title: item.title || '',
|
||||
pageCoverThumbnail: item.pageCoverThumbnail || '',
|
||||
category: item.category || null,
|
||||
tags: item.tags || null,
|
||||
summary: item.summary || null,
|
||||
slug: item.slug,
|
||||
pageIcon: item.pageIcon || '',
|
||||
lastEditedDate: item.lastEditedDate
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +215,15 @@ const EmptyData = (pageId) => {
|
||||
const empty = {
|
||||
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', lastEditedDay: '2023-04-24', tagItems: [] } }],
|
||||
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', lastEditedDay: '2023-04-24', tagItems: [] }
|
||||
}],
|
||||
allNavPages: [],
|
||||
collection: [],
|
||||
collectionQuery: {},
|
||||
@@ -263,9 +281,17 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
|
||||
const id = pageIds[i]
|
||||
const value = block[id]?.value
|
||||
if (!value) {
|
||||
// 如果找不到文章对应的block,说明发生了溢出,使用pageID再去请求
|
||||
const pageBlock = await getSingleBlock(id, from)
|
||||
if (pageBlock.block[id].value) {
|
||||
const properties = (await getPageProperties(id, pageBlock.block[id].value, schema, null, getTagOptions(schema))) || null
|
||||
if (properties) {
|
||||
collectionData.push(properties)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
const properties = (await getPageProperties(id, block, schema, null, getTagOptions(schema))) || null
|
||||
const properties = (await getPageProperties(id, block[id].value, schema, null, getTagOptions(schema))) || null
|
||||
if (properties) {
|
||||
collectionData.push(properties)
|
||||
}
|
||||
@@ -280,8 +306,8 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
|
||||
postCount++
|
||||
}
|
||||
return post && post?.slug &&
|
||||
(!post?.slug?.startsWith('http')) &&
|
||||
(post?.status === 'Invisible' || post?.status === 'Published')
|
||||
(!post?.slug?.startsWith('http')) &&
|
||||
(post?.status === 'Invisible' || post?.status === 'Published')
|
||||
})
|
||||
|
||||
// 站点配置优先读取配置表格,否则读取blog.config.js 文件
|
||||
@@ -294,7 +320,9 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
|
||||
})
|
||||
}
|
||||
|
||||
const notice = await getNotice(collectionData.filter(post => { return post && post?.type && post?.type === 'Notice' && post.status === 'Published' })?.[0])
|
||||
const notice = await getNotice(collectionData.filter(post => {
|
||||
return post && post?.type && post?.type === 'Notice' && post.status === 'Published'
|
||||
})?.[0])
|
||||
const categoryOptions = getAllCategories({ allPages, categoryOptions: getCategoryOptions(schema) })
|
||||
const tagOptions = getAllTags({ allPages, tagOptions: getTagOptions(schema) })
|
||||
// 旧的菜单
|
||||
|
||||
Reference in New Issue
Block a user