From 7e3ce211b1cea26a9a36f4404a09daec5d99af6c Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 31 Mar 2022 09:56:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E9=9D=A2=E5=9B=BE=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E9=93=BE=E6=8E=A5=E5=92=8C=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionData.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 4640633b..ea10fa0b 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -2,6 +2,7 @@ import BLOG from '@/blog.config' import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager' import { getPostBlocks } from '@/lib/notion/getPostBlocks' import { idToUuid } from 'notion-utils' +import { defaultMapImageUrl } from 'react-notion-x' import { getAllCategories } from './getAllCategories' import { getAllPosts, getAllPostCount } from './getAllPosts' import { getAllTags } from './getAllTags' @@ -158,7 +159,7 @@ async function getBlogInfo ({ notionPageData, from }) { const collection = notionPageData?.collection const title = collection?.name[0][0] || BLOG.TITLE const description = collection?.description[0][0] || BLOG.DESCRIPTION - const pageCover = mapCoverUrl(collection?.cover) + const pageCover = mapCoverUrl(collection?.cover, notionPageData.block) return { title, description, pageCover } } @@ -167,14 +168,13 @@ async function getBlogInfo ({ notionPageData, from }) { * @param pageCover * @returns {string} */ -const mapCoverUrl = pageCover => { +const mapCoverUrl = (pageCover, block) => { if (!pageCover || pageCover === '') { return BLOG.HOME_BANNER_IMAGE } - if (pageCover.indexOf('/images') === 0) { - return 'https://www.notion.so' + pageCover - } else { - return pageCover + if (pageCover) { + if (pageCover.startsWith('/')) return 'https://www.notion.so' + pageCover + if (pageCover.startsWith('http')) return defaultMapImageUrl(pageCover, block[idToUuid(BLOG.NOTION_PAGE_ID)].value) } }