Skip to content

Commit

Permalink
Merge pull request #241 from tangly1024/fix-deploy-icon
Browse files Browse the repository at this point in the history
修复站点图标为Emoji时的编译问题
  • Loading branch information
tangly1024 authored May 13, 2022
2 parents 7041858 + 7a0058f commit eaa6b90
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions lib/notion/getNotionData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -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 }
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/notion/getPostBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

1 comment on commit eaa6b90

@vercel
Copy link

@vercel vercel bot commented on eaa6b90 May 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.