From 4ad79ca7a222ffbb3e6fd6d710779a35a44e2a2f Mon Sep 17 00:00:00 2001 From: "tangly1024.com" Date: Wed, 7 Jun 2023 16:46:33 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=8E=8B=E7=BC=A9=E7=BD=91=E7=AB=99Noti?= =?UTF-8?q?on=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionData.js | 7 +++++-- lib/notion/mapImage.js | 11 ++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 9b586e65..26c6b891 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -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' /** * 获取博客数据 @@ -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)) { diff --git a/lib/notion/mapImage.js b/lib/notion/mapImage.js index 2169bf1d..54677344 100644 --- a/lib/notion/mapImage.js +++ b/lib/notion/mapImage.js @@ -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 @@ -32,4 +41,4 @@ const mapImgUrl = (img, block, type = 'block') => { return ret } -export { mapImgUrl } +export { mapImgUrl, compressImage }