fukasawa减少动画、并支持调整;

图片画质参数支持调节;
博客支持外链文章
This commit is contained in:
tangly1024.com
2024-02-01 15:25:07 +08:00
parent 66fc70e4f9
commit 022706bb40
43 changed files with 308 additions and 180 deletions

View File

@@ -1,4 +1,5 @@
import BLOG from '@/blog.config'
import { siteConfig } from '../config'
/**
* 图片映射
@@ -58,7 +59,7 @@ const mapImgUrl = (img, block, type = 'block', from = 'post') => {
// 统一压缩图片
if (from === 'pageCoverThumbnail' || block.type === 'image' || block.type === 'page') {
const width = block?.format?.block_width || 200
const width = block?.format?.block_width
ret = compressImage(ret, width)
}
@@ -81,19 +82,29 @@ function isEmoji(str) {
* 2. UnPlash 图片可以通过api q=50 控制压缩质量 width=400 控制图片尺寸
* @param {*} image
*/
const compressImage = (image, width = 800, quality = 50, fmt = 'webp') => {
if (!image) {
return null
const compressImage = (image, width, quality = 50, fmt = 'webp') => {
if (!image || image.indexOf('http') !== 0) {
return image
}
if (!width || width === 0) {
width = siteConfig('IMAGE_COMPRESS_WIDTH')
}
// 将URL解析为一个对象
const urlObj = new URL(image)
// 获取URL参数
const params = new URLSearchParams(urlObj.search)
// Notion图床
if (image.indexOf(BLOG.NOTION_HOST) === 0 && image.indexOf('amazonaws.com') > 0) {
return `${image}&width=${width}&cache=v2`
}
// 压缩unsplash图片
if (image.indexOf('https://images.unsplash.com/') === 0) {
// 将URL解析为一个对象
const urlObj = new URL(image)
// 获取URL参数
const params = new URLSearchParams(urlObj.search)
params.set('width', width)
params.set('cache', 'v2')
// 生成新的URL
urlObj.search = params.toString()
return urlObj.toString()
} else if (image.indexOf('https://images.unsplash.com/') === 0) {
// 压缩unsplash图片
// 将q参数的值替换
params.set('q', quality)
// 尺寸
@@ -104,11 +115,9 @@ const compressImage = (image, width = 800, quality = 50, fmt = 'webp') => {
// 生成新的URL
urlObj.search = params.toString()
return urlObj.toString()
}
// 此处还可以添加您的自定义图传的封面图压缩参数。
} else if (image.indexOf('https://your_picture_bed') === 0) {
// 此处还可以添加您的自定义图传的封面图压缩参数。
// .e.g
if (image.indexOf('https://your_picture_bed') === 0) {
return 'do_somethin_here'
}