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 <img src>
from HTML content to display these images.
This commit is contained in:
Paweł Orzech 2026-03-20 09:32:15 +01:00
parent d079fc9ba8
commit 84408075b7
No known key found for this signature in database

View file

@ -589,9 +589,11 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) {
} }
} }
private val imgSrcRegex = Regex("""<img[^>]+src\s*=\s*["']([^"']+)["']""", RegexOption.IGNORE_CASE)
private fun GhostPost.toFeedPost(): FeedPost { private fun GhostPost.toFeedPost(): FeedPost {
val mobiledocCards = parseMobiledocCards(mobiledoc) 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<String>() val allImages = mutableListOf<String>()
if (feature_image != null) { if (feature_image != null) {
allImages.add(feature_image) allImages.add(feature_image)
@ -601,6 +603,15 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) {
allImages.add(url) 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 val isEmailOnly = status == "sent" || email_only == true
return FeedPost( return FeedPost(
ghostId = id, ghostId = id,