mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-09 07:26:47 +00:00
修复封面图bug
This commit is contained in:
@@ -79,8 +79,8 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
|||||||
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
|
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
|
||||||
properties.lastEditedTime = formatDate(new Date(value?.last_edited_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.fullWidth = value.format?.page_full_width ?? false
|
||||||
properties.pageIcon = getPageIcon(id, block) ?? ''
|
properties.pageIcon = getImageUrl(block[id].value?.format?.page_icon, block[id].value) ?? ''
|
||||||
properties.page_cover = getPostCover(id, block) ?? siteInfo?.pageCover
|
properties.page_cover = getImageUrl(block[id].value?.format?.page_cover, block[id].value) ?? siteInfo?.pageCover
|
||||||
properties.content = value.content ?? []
|
properties.content = value.content ?? []
|
||||||
properties.tagItems = properties?.tags?.map(tag => {
|
properties.tagItems = properties?.tags?.map(tag => {
|
||||||
return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' }
|
return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' }
|
||||||
@@ -89,20 +89,23 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
|||||||
return properties
|
return properties
|
||||||
|
|
||||||
// 从Block获取封面图;优先取PageCover,否则取内容图片
|
// 从Block获取封面图;优先取PageCover,否则取内容图片
|
||||||
function getPostCover(id, block) {
|
function getImageUrl(imgObj, blockVal) {
|
||||||
const pageCover = block[id].value?.format?.page_cover
|
if (!imgObj) {
|
||||||
if (pageCover) {
|
return null
|
||||||
if (pageCover.startsWith('/')) return 'https://www.notion.so' + pageCover
|
}
|
||||||
if (pageCover.startsWith('http')) return defaultMapImageUrl(pageCover, block[id].value)
|
if (imgObj.startsWith('/')) {
|
||||||
|
return 'https://www.notion.so' + imgObj // notion内部图片转相对路径为绝对路径
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPageIcon(id, block) {
|
if (imgObj.startsWith('http')) {
|
||||||
const pageIcon = block[id].value?.format?.page_icon
|
// 判断如果是notion上传的图片要拼接访问token
|
||||||
if (pageIcon) {
|
const u = new URL(imgObj)
|
||||||
if (pageIcon.startsWith('/')) return 'https://www.notion.so' + pageIcon
|
if (u.pathname.startsWith('/secure.notion-static.com') && u.hostname.endsWith('.amazonaws.com')) {
|
||||||
if (pageIcon.startsWith('http')) return defaultMapImageUrl(pageIcon, block[id].value)
|
return defaultMapImageUrl(imgObj, blockVal) // notion上传的图片需要转换请求地址
|
||||||
return pageIcon
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 其他图片链接 或 emoji
|
||||||
|
return imgObj
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ import NotionPage from '@/components/NotionPage'
|
|||||||
|
|
||||||
const BlogPostCard = ({ post, showSummary }) => {
|
const BlogPostCard = ({ post, showSummary }) => {
|
||||||
const showPreview = CONFIG_HEXO.POST_LIST_PREVIEW && post.blockMap
|
const showPreview = CONFIG_HEXO.POST_LIST_PREVIEW && post.blockMap
|
||||||
const linkedCoverPrefix = 'https://www.notion.so/image/'
|
|
||||||
if (post?.page_cover && post?.page_cover?.startsWith(linkedCoverPrefix)) {
|
|
||||||
const linkedCoverPrefixLength = linkedCoverPrefix.length
|
|
||||||
post.page_cover = decodeURIComponent(post.page_cover.slice(linkedCoverPrefixLength))
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full shadow-sm hover:shadow border dark:border-black rounded-xl bg-white dark:bg-hexo-black-gray duration-300">
|
<div className="w-full shadow-sm hover:shadow border dark:border-black rounded-xl bg-white dark:bg-hexo-black-gray duration-300">
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user