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) } }