Skip to content

Commit

Permalink
Improve FreshRSS image preview parsing (#669)
Browse files Browse the repository at this point in the history
* Unescape & in image URLs

* Parse FreshRSS content for first image
  • Loading branch information
jocmp authored Jan 3, 2025
1 parent f2a21c2 commit bd395d0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import com.capyreader.app.ui.fixtures.ArticleSample
import com.capyreader.app.ui.theme.CapyTheme
import com.jocmp.capy.Article
import com.jocmp.capy.MarkRead
import com.jocmp.capy.common.escapingSpecialXMLCharacters
import java.net.URL
import java.time.LocalDateTime
import java.time.ZoneOffset
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.jocmp.capy.accounts.reader

import com.jocmp.capy.common.unescapingHTMLCharacters
import com.jocmp.readerclient.Item
import org.jsoup.Jsoup

internal fun parsedImageURL(item: Item): String? {
val imageHref = item.image?.href

if (imageHref != null) {
return imageHref.unescapingHTMLCharacters
}

val content = item.summary.content

return Jsoup.parse(content).selectFirst("img")?.attr("src")
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ internal class ReaderAccountDelegate(
extracted_content_url = null,
summary = Jsoup.parse(item.summary.content).text(),
url = item.canonical.firstOrNull()?.href,
image_url = item.image?.href,
image_url = parsedImageURL(item),
published_at = item.published
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ val String.escapingSpecialXMLCharacters: String

return escaped
}

val String.unescapingHTMLCharacters: String
get() {
return this
.replace("&", "&")
.replace("&lt;", "<")
.replace("&gt;", ">")
}

0 comments on commit bd395d0

Please sign in to comment.