From 1aa215bd1e959139bdd4a81c5d4dd44566f75007 Mon Sep 17 00:00:00 2001 From: tlyong1992 Date: Thu, 19 May 2022 16:09:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=A9=BA=E7=99=BD=E5=B0=81=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getAllPosts.js | 2 +- lib/notion/getNotionData.js | 10 ++++++---- lib/notion/getPageProperties.js | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index c853ffdd..69215527 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -28,7 +28,7 @@ export async function getAllPosts({ notionPageData, from, pageType }) { if (!value) { continue } - const properties = (await getPageProperties(id, block, schema, tagOptions)) || null + const properties = (await getPageProperties(id, block, schema, null, tagOptions, notionPageData.siteInfo)) || null data.push(properties) } diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 076a56c3..aa308e3d 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -27,8 +27,6 @@ export async function getGlobalNotionData({ }) { // 获取Notion数据 const notionPageData = deepClone(await getNotionPageData({ pageId, from })) - notionPageData.siteInfo = getBlogInfo({ collection: notionPageData?.collection, block: notionPageData?.block }) - // 获取文章列表 notionPageData.allPosts = await getAllPosts({ notionPageData, from, pageType }) delete notionPageData.block @@ -239,6 +237,7 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { const viewIds = rawMetadata?.view_ids const data = [] const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds) + const siteInfo = getBlogInfo({ collection, block }) if (pageIds?.length === 0) { console.error('获取到的文章列表为空,请检查notion模板', collectionQuery, collection, pageRecordMap) } @@ -248,8 +247,10 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { if (!value) { continue } - const properties = (await getPageProperties(id, block, schema, tagOptions)) || null - data.push(properties) + const properties = (await getPageProperties(id, block, schema, null, tagOptions, siteInfo)) || null + if (properties) { + data.push(properties) + } } const allPage = data.filter(post => { @@ -266,6 +267,7 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { const latestPosts = getLatestPosts({ allPosts, from, latestPostCount: 5 }) return { + siteInfo, collection, collectionQuery, collectionId, diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index ed43c44e..f95969da 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -4,7 +4,7 @@ import BLOG from '@/blog.config' import formatDate from '../formatDate' import { defaultMapImageUrl } from 'react-notion-x' -async function getPageProperties(id, block, schema, authToken, tagOptions) { +async function getPageProperties(id, block, schema, authToken, tagOptions, siteInfo) { const rawProperties = Object.entries(block?.[id]?.value?.properties || []) const excludeProperties = ['date', 'select', 'multi_select', 'person'] const value = block[id]?.value @@ -63,7 +63,7 @@ async function getPageProperties(id, block, schema, authToken, tagOptions) { properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG) properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG) properties.fullWidth = value.format?.page_full_width ?? false - properties.page_cover = getPostCover(id, block) ?? null + properties.page_cover = getPostCover(id, block) ?? siteInfo?.pageCover properties.content = value.content ?? [] properties.tagItems = properties?.tags?.map(tag => { return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' } From 4842c41f49f709d348111fe96a4dfb5fe1d5c6f0 Mon Sep 17 00:00:00 2001 From: tlyong1992 Date: Thu, 19 May 2022 16:22:47 +0800 Subject: [PATCH 2/3] Merge --- lib/notion/getNotionData.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 9d742a3b..b9e3ba4d 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -26,8 +26,6 @@ export async function getGlobalNotionData({ }) { // 获取Notion数据 const notionPageData = deepClone(await getNotionPageData({ pageId, from })) - // 获取文章列表 - notionPageData.allPosts = await getAllPosts({ notionPageData, from, pageType }) delete notionPageData.block delete notionPageData.collection delete notionPageData.collectionQuery From c68178a4024de19eeaff020bdb497a477f45c444 Mon Sep 17 00:00:00 2001 From: tlyong1992 Date: Thu, 19 May 2022 16:24:58 +0800 Subject: [PATCH 3/3] Merge --- lib/notion/getNotionData.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index b9e3ba4d..bf54561c 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -246,10 +246,9 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { if (!value) { continue } - collectionData.push(properties) const properties = (await getPageProperties(id, block, schema, null, tagOptions, siteInfo)) || null if (properties) { - data.push(properties) + collectionData.push(properties) } }