Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve FreshRSS image preview parsing #669

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;", ">")
}
Loading