mirror of
https://github.com/miniflux/v2.git
synced 2025-10-05 19:31:01 +00:00
feat(rewrite): add remove_img_blur_params
rule
Adds a new content rewrite rule to strip image URL query parameters from blurred images. This addresses issues with sites like Belgian national news that use blurry placeholder images which get replaced with high-quality versions, allowing Miniflux to fetch the original images instead of the placeholders.
This commit is contained in:
parent
04a360a536
commit
b8bc367a00
3 changed files with 200 additions and 3 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"log/slog"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
|
@ -547,3 +548,43 @@ func fixGhostCards(entryContent string) string {
|
|||
output, _ := doc.FindMatcher(goquery.Single("body")).Html()
|
||||
return strings.TrimSpace(output)
|
||||
}
|
||||
|
||||
func removeImgBlurParams(entryContent string) string {
|
||||
doc, err := goquery.NewDocumentFromReader(strings.NewReader(entryContent))
|
||||
if err != nil {
|
||||
return entryContent
|
||||
}
|
||||
|
||||
changed := false
|
||||
|
||||
doc.Find("img[src]").Each(func(i int, img *goquery.Selection) {
|
||||
srcAttr, exists := img.Attr("src")
|
||||
if !exists {
|
||||
return
|
||||
}
|
||||
|
||||
parsedURL, err := url.Parse(srcAttr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Only strip query parameters if this is a blurry placeholder image
|
||||
if parsedURL.RawQuery != "" {
|
||||
// Check if there's a blur parameter with a non-zero value
|
||||
if blurValue := parsedURL.Query().Get("blur"); blurValue != "" {
|
||||
if blurInt, err := strconv.Atoi(blurValue); err == nil && blurInt > 0 {
|
||||
parsedURL.RawQuery = ""
|
||||
img.SetAttr("src", parsedURL.String())
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if changed {
|
||||
output, _ := doc.FindMatcher(goquery.Single("body")).Html()
|
||||
return output
|
||||
}
|
||||
|
||||
return entryContent
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue