mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-07 23:16:52 +00:00
修复图片显示
This commit is contained in:
@@ -151,10 +151,10 @@ function getCategoryOptions(schema) {
|
|||||||
* @param from
|
* @param from
|
||||||
* @returns {Promise<{title,description,pageCover,icon}>}
|
* @returns {Promise<{title,description,pageCover,icon}>}
|
||||||
*/
|
*/
|
||||||
function getBlogInfo({ collection, block }) {
|
function getSiteInfo({ collection, block }) {
|
||||||
const title = collection?.name?.[0][0] || BLOG.TITLE
|
const title = collection?.name?.[0][0] || BLOG.TITLE
|
||||||
const description = collection?.description ? Object.assign(collection).description[0][0] : BLOG.DESCRIPTION
|
const description = collection?.description ? Object.assign(collection).description[0][0] : BLOG.DESCRIPTION
|
||||||
const pageCover = collection?.cover ? (mapImgUrl(collection?.cover, block[idToUuid(BLOG.NOTION_PAGE_ID)]?.value)) : BLOG.HOME_BANNER_IMAGE
|
const pageCover = collection?.cover ? mapImgUrl(collection?.cover, block[idToUuid(BLOG.NOTION_PAGE_ID)]?.value) : BLOG.HOME_BANNER_IMAGE
|
||||||
let icon = collection?.icon ? mapImgUrl(collection?.icon, collection, 'collection') : BLOG.AVATAR
|
let icon = collection?.icon ? mapImgUrl(collection?.icon, collection, 'collection') : BLOG.AVATAR
|
||||||
|
|
||||||
// 用户头像压缩一下
|
// 用户头像压缩一下
|
||||||
@@ -181,7 +181,7 @@ async function getNotice(post) {
|
|||||||
const EmptyData = (pageId) => {
|
const EmptyData = (pageId) => {
|
||||||
const empty = {
|
const empty = {
|
||||||
notice: null,
|
notice: null,
|
||||||
siteInfo: getBlogInfo({}),
|
siteInfo: getSiteInfo({}),
|
||||||
allPages: [{ id: 1, title: `无法获取Notion数据,请检查Notion_ID: \n 当前 ${pageId}`, summary: '访问文档获取帮助→ https://tangly1024.com/article/vercel-deploy-notion-next', status: 'Published', type: 'Post', slug: '13a171332816461db29d50e9f575b00d', date: { start_date: '2023-04-24', lastEditedTime: '2023-04-24', tagItems: [] } }],
|
allPages: [{ id: 1, title: `无法获取Notion数据,请检查Notion_ID: \n 当前 ${pageId}`, summary: '访问文档获取帮助→ https://tangly1024.com/article/vercel-deploy-notion-next', status: 'Published', type: 'Post', slug: '13a171332816461db29d50e9f575b00d', date: { start_date: '2023-04-24', lastEditedTime: '2023-04-24', tagItems: [] } }],
|
||||||
collection: [],
|
collection: [],
|
||||||
collectionQuery: {},
|
collectionQuery: {},
|
||||||
@@ -223,7 +223,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
|
|||||||
return EmptyData(pageId)
|
return EmptyData(pageId)
|
||||||
}
|
}
|
||||||
const collection = Object.values(pageRecordMap.collection)[0]?.value || {}
|
const collection = Object.values(pageRecordMap.collection)[0]?.value || {}
|
||||||
const siteInfo = getBlogInfo({ collection, block })
|
const siteInfo = getSiteInfo({ collection, block })
|
||||||
const collectionId = rawMetadata?.collection_id
|
const collectionId = rawMetadata?.collection_id
|
||||||
const collectionQuery = pageRecordMap.collection_query
|
const collectionQuery = pageRecordMap.collection_query
|
||||||
const collectionView = pageRecordMap.collection_view
|
const collectionView = pageRecordMap.collection_view
|
||||||
|
|||||||
@@ -9,29 +9,37 @@ const compressImage = (image) => {
|
|||||||
return image + '&width=200'
|
return image + '&width=200'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notion图片映射处理有emoji的图标
|
* 图片映射
|
||||||
|
* 1. 如果是 /xx.xx 相对路径格式,则转化为 完整notion域名图片
|
||||||
|
* 2. 如果是 bookmark类型的block 图片封面无需处理
|
||||||
* @param {*} img
|
* @param {*} img
|
||||||
* @param {*} value
|
* @param {*} value
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
const mapImgUrl = (img, block, type = 'block') => {
|
const mapImgUrl = (img, block, type = 'block') => {
|
||||||
let ret = null
|
|
||||||
if (!img) {
|
if (!img) {
|
||||||
return ret
|
return null
|
||||||
}
|
}
|
||||||
|
let ret = null
|
||||||
// 相对目录,则视为notion的自带图片
|
// 相对目录,则视为notion的自带图片
|
||||||
if (img.startsWith('/')) {
|
if (img.startsWith('/')) {
|
||||||
ret = BLOG.NOTION_HOST + img
|
ret = BLOG.NOTION_HOST + img
|
||||||
}
|
} else {
|
||||||
// 书签的地址本身就是永久链接,无需处理
|
|
||||||
if (!ret && block?.type === 'bookmark') {
|
|
||||||
ret = img
|
ret = img
|
||||||
}
|
}
|
||||||
// notion永久图床地址
|
|
||||||
if (!ret && ret !== null && ret.indexOf('secure.notion-static.com') > 0 && (BLOG.IMG_URL_TYPE === 'Notion' || type !== 'block')) {
|
// 书签的地址本身就是永久链接,无需处理
|
||||||
|
if (block?.type === 'bookmark') {
|
||||||
|
ret = img
|
||||||
|
}
|
||||||
|
|
||||||
|
// notion 图床转换为永久图床地址
|
||||||
|
if (ret.indexOf('secure.notion-static.com') > 0 && (BLOG.IMG_URL_TYPE === 'Notion' || type !== 'block')) {
|
||||||
ret = BLOG.NOTION_HOST + '/image/' + encodeURIComponent(ret) + '?table=' + type + '&id=' + block.id
|
ret = BLOG.NOTION_HOST + '/image/' + encodeURIComponent(ret) + '?table=' + type + '&id=' + block.id
|
||||||
}
|
}
|
||||||
|
console.log('图床', ret)
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user