mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Add data-srcset support to "add_dynamic_image rewrite" rewrite rule
This commit is contained in:
parent
d45e1b3bed
commit
b585dab6b4
2 changed files with 41 additions and 0 deletions
|
@ -100,9 +100,14 @@ func addDynamicImage(entryURL, entryContent string) string {
|
|||
"data-380src",
|
||||
}
|
||||
|
||||
candidateSrcsetAttrs := []string{
|
||||
"data-srcset",
|
||||
}
|
||||
|
||||
changed := false
|
||||
|
||||
doc.Find("img,div").Each(func(i int, img *goquery.Selection) {
|
||||
// Src-linked candidates
|
||||
for _, candidateAttr := range candidateAttrs {
|
||||
if srcAttr, found := img.Attr(candidateAttr); found {
|
||||
changed = true
|
||||
|
@ -117,6 +122,22 @@ func addDynamicImage(entryURL, entryContent string) string {
|
|||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Srcset-linked candidates
|
||||
for _, candidateAttr := range candidateSrcsetAttrs {
|
||||
if srcAttr, found := img.Attr(candidateAttr); found {
|
||||
changed = true
|
||||
|
||||
if img.Is("img") {
|
||||
img.SetAttr("srcset", srcAttr)
|
||||
} else {
|
||||
altAttr := img.AttrOr("alt", "")
|
||||
img.ReplaceWithHtml(`<img srcset="` + srcAttr + `" alt="` + altAttr + `"/>`)
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if !changed {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue