Skip to content

Commit

Permalink
🐛 No optimization for gif svg images
Browse files Browse the repository at this point in the history
  • Loading branch information
tw93 committed Apr 2, 2024
1 parent 22a4909 commit 042adee
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions _plugins/cdn_image_filter.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# Optimize the images of CDN using OSS rules.
# Optimize the images of CDN using OSS rules, except for GIF and SVG images.
# Usage: {{ content | cdn_image_filter }}
module Jekyll
module CDNImageFilter
def cdn_image_filter(input)
input.gsub(/<img src="(https:\/\/cdn\.fliggy\.com\/.*?|https:\/\/gw\.alipayobjects\.com\/.*?)"/) do |match|
input.gsub(/<img src="(https:\/\/cdn\.fliggy\.com\/.*?|https:\/\/gw\.alipayobjects\.com\/.*?)(\.(jpg|jpeg|png|JPG|JPEG|PNG))"/) do |match|
src = $1
if src.start_with?('https://cdn.fliggy.com') || src.start_with?('https://gw.alipayobjects.com')
"#{match.chomp('"')}?x-oss-process=image/resize,w_3600/format,webp\""
else
extension = $2.downcase # 获取文件扩展名并转换为小写
# 检查是否为GIF或SVG图片,如果是,则不修改
if extension == ".gif" || extension == ".svg"
match
else
if src.start_with?('https://cdn.fliggy.com') || src.start_with?('https://gw.alipayobjects.com')
"#{match.chomp('"')}?x-oss-process=image/resize,w_3600/format,webp\""
else
match
end
end
end
end
Expand Down

0 comments on commit 042adee

Please sign in to comment.