From 84408075b71d6a9db4f712dda029edf0c7a1e071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Orzech?= Date: Fri, 20 Mar 2026 09:32:15 +0100 Subject: [PATCH] fix: extract images from HTML content when feature_image and mobiledoc cards are empty Posts may have images embedded in HTML (via html/markdown cards) without a feature_image or explicit image card. Fall back to parsing from HTML content to display these images. --- .../com/swoosh/microblog/ui/feed/FeedViewModel.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/swoosh/microblog/ui/feed/FeedViewModel.kt b/app/src/main/java/com/swoosh/microblog/ui/feed/FeedViewModel.kt index 4565db1..b8695ec 100644 --- a/app/src/main/java/com/swoosh/microblog/ui/feed/FeedViewModel.kt +++ b/app/src/main/java/com/swoosh/microblog/ui/feed/FeedViewModel.kt @@ -589,9 +589,11 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) { } } + private val imgSrcRegex = Regex("""]+src\s*=\s*["']([^"']+)["']""", RegexOption.IGNORE_CASE) + private fun GhostPost.toFeedPost(): FeedPost { val mobiledocCards = parseMobiledocCards(mobiledoc) - // Use feature_image as primary, then add mobiledoc images (avoiding duplicates) + // Use feature_image as primary, then add mobiledoc images, then HTML images (avoiding duplicates) val allImages = mutableListOf() if (feature_image != null) { allImages.add(feature_image) @@ -601,6 +603,15 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) { allImages.add(url) } } + // Fallback: extract images from HTML content + if (allImages.isEmpty() && html != null) { + imgSrcRegex.findAll(html).forEach { match -> + val url = match.groupValues[1] + if (url !in allImages) { + allImages.add(url) + } + } + } val isEmailOnly = status == "sent" || email_only == true return FeedPost( ghostId = id,