Skip to content

Commit

Permalink
Remove cleanTextCompact from FeedParser
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Aug 9, 2024
1 parent 8e4e107 commit d941f0f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(),
Expand Down

0 comments on commit d941f0f

Please sign in to comment.