mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 23:16:49 +00:00
修复思路是在加载所有文章时,会首先一次性加载数据库中所有block,此时因为上限1000会发生溢出。之后会读取所有page的IDs,然后逐个获取page对应的block。此时如果发现ID查找不到(说明发生了溢出),则再调用API去逐一获取这些溢出了的page。可能这不是最优解。 修改的代码包括: 1. getDataBaseInfoByNotionAPI中添加上述判断逻辑。 2. 修改getPageProperties函数签名,直接传入block对应的value,而不是block数组。
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import BLOG from '@/blog.config'
|
|
import getAllPageIds from './getAllPageIds'
|
|
import getPageProperties from './getPageProperties'
|
|
import { getNotionPageData } from '@/lib/notion/getNotionData'
|
|
import { delCacheData } from '@/lib/cache/cache_manager'
|
|
|
|
/**
|
|
* 获取所有文章列表
|
|
* @param notionPageData
|
|
* @param from
|
|
* @param pageType 页面类型数组 ['Post','Page']
|
|
* @returns {Promise<*[]>}
|
|
*/
|
|
export async function getAllPosts({ notionPageData, from, pageType }) {
|
|
if (!notionPageData) {
|
|
notionPageData = await getNotionPageData({ from })
|
|
}
|
|
if (!notionPageData) {
|
|
return []
|
|
}
|
|
|
|
const { block, schema, tagOptions, collectionQuery, collectionId, collectionView, viewIds } = notionPageData
|
|
const data = []
|
|
const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds)
|
|
for (let i = 0; i < pageIds.length; i++) {
|
|
const id = pageIds[i]
|
|
const value = block[id]?.value
|
|
if (!value) {
|
|
continue
|
|
}
|
|
const properties = (await getPageProperties(id, block[id].value, schema, null, tagOptions)) || null
|
|
data.push(properties)
|
|
}
|
|
|
|
// remove all the the items doesn't meet requirements
|
|
const posts = data.filter(post => {
|
|
return post.title && post?.status?.[0] === 'Published' && pageType.indexOf(post?.type?.[0]) > -1
|
|
})
|
|
|
|
if (!posts || posts.length === 0) {
|
|
const cacheKey = 'page_block_' + BLOG.NOTION_PAGE_ID
|
|
await delCacheData(cacheKey)
|
|
}
|
|
|
|
// Sort by date
|
|
if (BLOG.POSTS_SORT_BY === 'date') {
|
|
posts.sort((a, b) => {
|
|
return b?.publishDate - a?.publishDate
|
|
})
|
|
}
|
|
return posts
|
|
}
|