[feat] 支持随机图片 url 统一配置

This commit is contained in:
zhangjiashu
2023-11-10 12:47:27 +08:00
parent 56c35d2a66
commit 4c483a71fe
2 changed files with 28 additions and 0 deletions

View File

@@ -68,6 +68,26 @@ const mapImgUrl = (img, block, type = 'block', from) => {
}
if (!isEmoji(ret) && ret.indexOf('notion.so/images/page-cover') < 0) {
if (BLOG.RANDOM_IMAGE_URL) {
// 只有配置了随机图片接口,才会替换图片
const texts = BLOG.RANDOM_IMAGE_REPLACE_TEXT
let isReplace = false;
if (texts) {
const textArr = texts.split(',')
// 判断是否包含替换的文本
textArr.forEach(text => {
if (ret.indexOf(text) > -1) {
isReplace = true
}
})
} else {
isReplace = true
}
if (isReplace) {
ret = BLOG.RANDOM_IMAGE_URL
}
}
// 随机图片接口优化 防止因url一致而随机结果相同
const separator = ret.includes('?') ? '&' : '?'
// 拼接唯一识别参数,防止请求的图片被缓存