From d941f0fa988fd25fb1571e0f84f536a0bcb8a113 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Fri, 9 Aug 2024 10:43:17 +0530 Subject: [PATCH] Remove `cleanTextCompact` from `FeedParser` --- .../rss/reader/core/network/parser/AtomContentParser.kt | 9 +++------ .../rss/reader/core/network/parser/FeedParser.kt | 2 -- .../rss/reader/core/network/parser/RDFContentParser.kt | 9 +++------ .../rss/reader/core/network/parser/RSSContentParser.kt | 9 +++------ 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/AtomContentParser.kt b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/AtomContentParser.kt index 615962a23..5aa35f295 100644 --- a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/AtomContentParser.kt +++ b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/AtomContentParser.kt @@ -123,11 +123,8 @@ internal object AtomContentParser : ContentParser() { rawContent = parser.nextText().trimIndent() val htmlContent = HtmlContentParser.parse(htmlContent = rawContent) - if (image.isNullOrBlank() && htmlContent != null) { - image = htmlContent.leadImage - } - - content = htmlContent?.content?.ifBlank { rawContent.trim() } ?: rawContent.trim() + image = htmlContent?.leadImage ?: image + content = htmlContent?.content?.ifBlank { null } ?: rawContent.trim() } TAG_PUBLISHED, TAG_UPDATED -> { @@ -150,7 +147,7 @@ internal object AtomContentParser : ContentParser() { return PostPayload( link = FeedParser.cleanText(link)!!, title = FeedParser.cleanText(title).orEmpty().decodeHTMLString(), - description = FeedParser.cleanTextCompact(content).orEmpty().decodeHTMLString(), + description = content.orEmpty().decodeHTMLString(), rawContent = rawContent, imageUrl = FeedParser.safeUrl(hostLink, image), date = postPubDateInMillis ?: Clock.System.now().toEpochMilliseconds(), diff --git a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/FeedParser.kt b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/FeedParser.kt index ffda49fc6..1a4e1e1a1 100644 --- a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/FeedParser.kt +++ b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/FeedParser.kt @@ -108,8 +108,6 @@ class FeedParser(private val dispatchersProvider: DispatchersProvider) { fun cleanText(text: String?) = text?.replace(htmlTag, "")?.replace(blankLine, "")?.trim() - fun cleanTextCompact(text: String?) = cleanText(text)?.take(300) - fun feedIcon(host: String): String { return "https://icon.horse/icon/$host" } diff --git a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/RDFContentParser.kt b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/RDFContentParser.kt index caeb2d5a4..cf736ea47 100644 --- a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/RDFContentParser.kt +++ b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/RDFContentParser.kt @@ -127,11 +127,8 @@ internal object RDFContentParser : ContentParser() { rawContent = parser.nextText().trimIndent() val htmlContent = HtmlContentParser.parse(htmlContent = rawContent) - if (image.isNullOrBlank() && htmlContent != null) { - image = htmlContent.leadImage - } - - description = htmlContent?.content?.ifBlank { rawContent.trim() } ?: rawContent.trim() + image = htmlContent?.leadImage ?: image + description = htmlContent?.content?.ifBlank { null } ?: rawContent.trim() } name == TAG_PUB_DATE || name == TAG_DC_DATE -> { date = parser.nextText() @@ -149,7 +146,7 @@ internal object RDFContentParser : ContentParser() { return PostPayload( link = FeedParser.cleanText(link)!!, title = FeedParser.cleanText(title).orEmpty().decodeHTMLString(), - description = FeedParser.cleanTextCompact(description).orEmpty().decodeHTMLString(), + description = description.orEmpty().decodeHTMLString(), rawContent = rawContent, imageUrl = FeedParser.safeUrl(hostLink, image), date = postPubDateInMillis ?: Clock.System.now().toEpochMilliseconds(), diff --git a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/RSSContentParser.kt b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/RSSContentParser.kt index f550c14a9..fcff82ee1 100644 --- a/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/RSSContentParser.kt +++ b/core/network/src/commonMain/kotlin/dev/sasikanth/rss/reader/core/network/parser/RSSContentParser.kt @@ -127,11 +127,8 @@ internal object RSSContentParser : ContentParser() { rawContent = parser.nextText().trimIndent() val htmlContent = HtmlContentParser.parse(htmlContent = rawContent) - if (image.isNullOrBlank() && htmlContent != null) { - image = htmlContent.leadImage - } - - description = htmlContent?.content?.ifBlank { rawContent.trim() } ?: rawContent.trim() + image = htmlContent?.leadImage ?: image + description = htmlContent?.content?.ifBlank { null } ?: rawContent.trim() } name == TAG_PUB_DATE -> { date = parser.nextText() @@ -158,7 +155,7 @@ internal object RSSContentParser : ContentParser() { return PostPayload( link = FeedParser.cleanText(link)!!, title = FeedParser.cleanText(title).orEmpty().decodeHTMLString(), - description = FeedParser.cleanTextCompact(description).orEmpty().decodeHTMLString(), + description = description.orEmpty().decodeHTMLString(), rawContent = rawContent, imageUrl = FeedParser.safeUrl(hostLink, image), date = postPubDateInMillis ?: Clock.System.now().toEpochMilliseconds(),