diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 0b13db15..076a56c3 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -27,6 +27,7 @@ export async function getGlobalNotionData({ }) { // 获取Notion数据 const notionPageData = deepClone(await getNotionPageData({ pageId, from })) + notionPageData.siteInfo = getBlogInfo({ collection: notionPageData?.collection, block: notionPageData?.block }) // 获取文章列表 notionPageData.allPosts = await getAllPosts({ notionPageData, from, pageType }) @@ -161,13 +162,13 @@ function getAllCategories({ allPosts, categoryOptions, sliceCount = 0 }) { * 站点信息 * @param notionPageData * @param from - * @returns {Promise<{title,description,pageCover}>} + * @returns {Promise<{title,description,pageCover,icon}>} */ function getBlogInfo({ collection, block }) { const title = collection?.name?.[0][0] || BLOG.TITLE - const description = 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 icon = collection?.icon ? mapCollectionImg(collection?.icon, collection) : BLOG.AVATAR + 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 icon = collection?.icon ? (mapCollectionImg(collection?.icon, collection)) : BLOG.AVATAR return { title, description, pageCover, icon } } @@ -195,6 +196,15 @@ const mapCollectionImg = (img, value) => { if (img.startsWith('http')) { return 'https://www.notion.so/image/' + encodeURIComponent(img) + '?table=collection&id=' + value.id } + // 判断是否含有emoji表情 + const emojiPattern = /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g + if (emojiPattern.test(img)) { + console.error('请不要使用emoji作为站点图标', img) + return BLOG.AVATAR + } + + console.error('非法的站点图标', img) + return BLOG.AVATAR } } @@ -254,10 +264,8 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) { const categories = getAllCategories({ allPosts, categoryOptions, sliceCount: BLOG.PREVIEW_CATEGORY_COUNT }) const tags = getAllTags({ allPosts, tagOptions, sliceCount: BLOG.PREVIEW_TAG_COUNT }) const latestPosts = getLatestPosts({ allPosts, from, latestPostCount: 5 }) - const siteInfo = getBlogInfo({ collection: collection, block: block }) return { - siteInfo, collection, collectionQuery, collectionId, diff --git a/lib/notion/getPostBlocks.js b/lib/notion/getPostBlocks.js index ebc770d9..50e80032 100644 --- a/lib/notion/getPostBlocks.js +++ b/lib/notion/getPostBlocks.js @@ -33,7 +33,7 @@ async function getPageWithRetry(id, from, retryAttempts = 3) { console.log('[请求API]', `from:${from}`, `id:${id}`, retryAttempts < 3 ? `剩余重试次数:${retryAttempts}` : '') try { const authToken = BLOG.NOTION_ACCESS_TOKEN || null - const api = new NotionAPI({ authToken }) + const api = new NotionAPI({ authToken, userTimeZone: 'Asia/ShangHai' }) const pageData = await api.getPage(id) console.info('[响应成功]:', `from:${from}`, `id:${id}`) return pageData diff --git a/package.json b/package.json index c4eb488b..0cc4a8a2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "lodash.throttle": "^4.1.1", "memory-cache": "^0.2.0", "next": "^12.0.5", - "notion-client": "6.10.0", + "notion-client": "6.12.9", "notion-utils": "6.10.0", "preact": "^10.5.15", "qrcode.react": "^1.0.1",