fix-修复编译问题

This commit is contained in:
tangly1024.com
2023-06-16 17:06:56 +08:00
parent 112f003d29
commit 20917b47a4
3 changed files with 36 additions and 36 deletions

View File

@@ -28,7 +28,7 @@ export async function getAllPosts({ notionPageData, from, pageType }) {
if (!value) {
continue
}
const properties = (await getPageProperties(id, block, schema, null, tagOptions, notionPageData.siteInfo)) || null
const properties = (await getPageProperties(id, block, schema, null, tagOptions)) || null
data.push(properties)
}

View File

@@ -65,7 +65,7 @@ export async function getNotionPageData({ pageId, from }) {
const cacheKey = 'page_block_' + pageId
const data = await getDataFromCache(cacheKey)
if (data && data.pageIds?.length > 0) {
console.log('[缓存]:', `from:${from}`, `root-page-id:${pageId}`)
console.log('[缓存]:', `from:${from}`, `root-page-id:${pageId}`, data)
return data
}
const pageRecordMap = await getDataBaseInfoByNotionAPI({ pageId, from })
@@ -156,12 +156,13 @@ function getBlogInfo({ collection, block }) {
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
let icon = collection?.icon ? mapImgUrl(collection?.icon, collection, 'collection') : BLOG.AVATAR
// 用户头像压缩一下
icon = compressImage(icon)
// 站点图标不能是emoji情
const emojiPattern = /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g
if (emojiPattern.test(icon)) {
if (!icon || emojiPattern.test(icon)) {
icon = BLOG.AVATAR
}
return { title, description, pageCover, icon }
@@ -176,6 +177,31 @@ async function getNotice(post) {
return post
}
// 没有数据时返回
const EmptyData = (pageId) => {
const empty = {
notice: null,
siteInfo: getBlogInfo({}),
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: [],
collectionQuery: {},
collectionId: null,
collectionView: {},
viewIds: [],
block: {},
schema: {},
tagOptions: [],
categoryOptions: [],
rawMetadata: {},
customNav: [],
customMenu: [],
postCount: 1,
pageIds: [],
latestPosts: []
}
return empty
}
/**
* 调用NotionAPI获取Page数据
* @returns {Promise<JSX.Element|null|*>}
@@ -194,28 +220,8 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
rawMetadata?.type !== 'collection_view_page' && rawMetadata?.type !== 'collection_view'
) {
console.error(`pageId "${pageId}" is not a database`)
return {
notice: null,
siteInfo: getBlogInfo({}),
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: [],
collectionQuery: {},
collectionId: null,
collectionView: {},
viewIds: [],
block: {},
schema: {},
tagOptions: [],
categoryOptions: [],
rawMetadata: {},
customNav: [],
customMenu: [],
postCount: 1,
pageIds: [],
latestPosts: []
}
return EmptyData(pageId)
}
const collection = Object.values(pageRecordMap.collection)[0]?.value || {}
const siteInfo = getBlogInfo({ collection, block })
const collectionId = rawMetadata?.collection_id

View File

@@ -5,7 +5,7 @@ import BLOG from '@/blog.config'
* @param {*} image
*/
const compressImage = (image) => {
if (image.indexOf(BLOG.NOTION_HOST) === 0) {
if (image && image.indexOf(BLOG.NOTION_HOST) === 0) {
return image + '&width=200'
}
}
@@ -21,23 +21,17 @@ const mapImgUrl = (img, block, type = 'block') => {
return ret
}
// 相对目录则视为notion的自带图片
if (img.startsWith('/')) ret = BLOG.NOTION_HOST + img
if (img.startsWith('/')) {
ret = BLOG.NOTION_HOST + img
}
// 书签的地址本身就是永久链接,无需处理
if (!ret && block?.type === 'bookmark') {
ret = img
}
// notion永久图床地址
if (!ret && img.indexOf('secure.notion-static.com') > 0 && (BLOG.IMG_URL_TYPE === 'Notion' || type !== 'block')) {
ret = BLOG.NOTION_HOST + '/image/' + encodeURIComponent(img) + '?table=' + type + '&id=' + block.id
if (!ret && ret !== null && 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
}
// 剩余的是第三方图片url或emoji
if (!ret) {
ret = img
}
return ret
}