Skip to content

Commit

Permalink
Reintroduce cleanLinks
Browse files Browse the repository at this point in the history
  • Loading branch information
jocmp committed Nov 12, 2024
1 parent 77b9d94 commit 364588f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ArticleRenderer(
document.getElementById("article-body-content")?.append(article.content)

cleanStyles(document)
cleanLinks(document)

return document.html()
}
Expand Down
17 changes: 17 additions & 0 deletions capy/src/main/java/com/jocmp/capy/articles/CleanLinks.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jocmp.capy.articles

import org.jsoup.nodes.Element

internal fun cleanLinks(element: Element) {
element.getElementsByTag("img").forEachIndexed{ index, child ->
child.attr("src", child.absUrl("src"))

if (index > 0) {
child.attr("loading", "lazy")
}
}

element.select("img[data-src]").forEach { child ->
child.attr("src", child.absUrl("data-src"))
}
}

0 comments on commit 364588f

Please sign in to comment.