Merge pull request #241 from tangly1024/fix-deploy-icon

修复站点图标为Emoji时的编译问题
This commit is contained in:
tangly1024
2022-05-13 12:50:45 +08:00
committed by GitHub
3 changed files with 16 additions and 8 deletions

View File

@@ -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,

View File

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

View File

@@ -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",