From 63ede093a82d976d6fdf94f7162406868a212c7a Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sun, 18 Jun 2023 11:14:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E5=BA=8A=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/mapImage.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/notion/mapImage.js b/lib/notion/mapImage.js index 0dae6ab9..ea30fbfc 100644 --- a/lib/notion/mapImage.js +++ b/lib/notion/mapImage.js @@ -7,11 +7,14 @@ import BLOG from '@/blog.config' * @param {*} image */ const compressImage = (image, width = 400) => { - if (image && image.indexOf(BLOG.NOTION_HOST) === 0) { + if (!image) { + return null + } + if (image.indexOf(BLOG.NOTION_HOST) === 0) { return `${image}&width=${width}` } // 压缩unsplash图片 - if (image && image.indexOf('https://images.unsplash.com/') === 0) { + if (image.indexOf('https://images.unsplash.com/') === 0) { // 将URL解析为一个对象 const urlObj = new URL(image) // 获取URL参数 @@ -27,6 +30,12 @@ const compressImage = (image, width = 400) => { return urlObj.toString() } + // 此处还可以添加您的自定义图传的封面图压缩参数。 + // .e.g + if (image.indexOf('https://your_picture_bed') === 0) { + return 'do_somethin_here' + } + return image }