Merge pull request #130 from tangly1024/preview

封面图支持外部链接和上传
This commit is contained in:
tangly1024
2022-03-31 09:59:32 +08:00
committed by GitHub

View File

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