diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 0e2d5bcb..55c15678 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -68,7 +68,7 @@ export async function getNotionPageData({ pageId, from }) { console.log('[命中缓存]:', `from:${from}`, `root-page-id:${pageId}`) return data } - const pageRecordMap = await getPageRecordMapByNotionAPI({ pageId, from }) + const pageRecordMap = await getDataBaseInfoByNotionAPI({ pageId, from }) // 存入缓存 if (pageRecordMap) { await setDataToCache(cacheKey, pageRecordMap) @@ -177,24 +177,44 @@ async function getNotice(post) { * 调用NotionAPI获取Page数据 * @returns {Promise} */ -async function getPageRecordMapByNotionAPI({ pageId, from }) { +async function getDataBaseInfoByNotionAPI({ pageId, from }) { const pageRecordMap = await getPostBlocks(pageId, from) if (!pageRecordMap) { - return [] + console.error('can`t get Notion Data ; Which id is: ', pageId) + return {} } pageId = idToUuid(pageId) - const block = pageRecordMap.block + const block = pageRecordMap.block || {} const rawMetadata = block[pageId]?.value // Check Type Page-Database和Inline-Database if ( - rawMetadata?.type !== 'collection_view_page' && - rawMetadata?.type !== 'collection_view' + rawMetadata?.type !== 'collection_view_page' && rawMetadata?.type !== 'collection_view' ) { - console.warn(`pageId "${pageId}" is not a database`) - return null + console.error(`pageId "${pageId}" is not a database`) + return { + notice: null, + siteInfo: getBlogInfo({}), + 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: [] } }], + collection: [], + collectionQuery: {}, + collectionId: null, + collectionView: {}, + viewIds: [], + block: {}, + schema: {}, + tagOptions: [], + categoryOptions: [], + rawMetadata: {}, + customNav: [], + customMenu: [], + postCount: 1, + pageIds: [], + latestPosts: [] + } } - const collection = Object.values(pageRecordMap.collection)[0]?.value + const collection = Object.values(pageRecordMap.collection)[0]?.value || {} + const siteInfo = getBlogInfo({ collection, block }) const collectionId = rawMetadata?.collection_id const collectionQuery = pageRecordMap.collection_query const collectionView = pageRecordMap.collection_view @@ -242,7 +262,6 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { 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) }) - const siteInfo = getBlogInfo({ collection, block }) const customNav = getCustomNav({ allPages: collectionData.filter(post => post.type === 'Page' && post.status === 'Published') }) // 新的菜单 const customMenu = await getCustomMenu({ collectionData }) diff --git a/themes/hexo/components/BlogPostCardInfo.js b/themes/hexo/components/BlogPostCardInfo.js index 88ceaeed..7336b64a 100644 --- a/themes/hexo/components/BlogPostCardInfo.js +++ b/themes/hexo/components/BlogPostCardInfo.js @@ -78,7 +78,7 @@ export const BlogPostCardInfo = ({ post, showPreview, showPageCover, showSummary
{' '} - {post.tagItems.map(tag => ( + {post.tagItems?.map(tag => ( ))}
diff --git a/themes/next/components/BlogPostCard.js b/themes/next/components/BlogPostCard.js index ad45b4a3..c10545a3 100644 --- a/themes/next/components/BlogPostCard.js +++ b/themes/next/components/BlogPostCard.js @@ -60,7 +60,7 @@ const BlogPostCard = ({ post, showSummary }) => {
{' '} - {post.tagItems.map(tag => ( + {post.tagItems?.map(tag => ( ))}