Skip to content

Commit

Permalink
Merge pull request tangly1024#1113 from tangly1024/fix/website-perfor…
Browse files Browse the repository at this point in the history
…mance

feat 压缩网站Notion头像
  • Loading branch information
tangly1024 committed Jun 7, 2023
2 parents 49aa528 + 4ad79ca commit 5bc414e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/notion/getNotionData.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getAllCategories } from './getAllCategories'
import getAllPageIds from './getAllPageIds'
import { getAllTags } from './getAllTags'
import getPageProperties from './getPageProperties'
import { mapImgUrl } from './mapImage'
import { mapImgUrl, compressImage } from './mapImage'

/**
* 获取博客数据
Expand Down Expand Up @@ -155,7 +155,10 @@ function getBlogInfo({ collection, block }) {
const title = collection?.name?.[0][0] || BLOG.TITLE
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
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)) {
Expand Down
11 changes: 10 additions & 1 deletion lib/notion/mapImage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import BLOG from '@/blog.config'

/**
* notion图片可以通过指定url-query参数来压缩裁剪图片 例如 ?width=200
* @param {*} image
*/
const compressImage = (image) => {
if (image.indexOf(BLOG.NOTION_HOST) === 0) {
return image + '&width=200'
}
}
/**
* Notion图片映射处理有emoji的图标
* @param {*} img
Expand Down Expand Up @@ -32,4 +41,4 @@ const mapImgUrl = (img, block, type = 'block') => {
return ret
}

export { mapImgUrl }
export { mapImgUrl, compressImage }

0 comments on commit 5bc414e

Please sign in to comment.