图床压缩

This commit is contained in:
tangly1024
2023-06-18 11:14:34 +08:00
parent 437f969115
commit 63ede093a8

View File

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