Skip to content

Commit a1e6ec1

Browse files
committed
Fix links in embedded mode
1 parent 21fb60c commit a1e6ec1

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

app/src/main/kotlin/org/vestifeed/api/standalone/StandaloneApi.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,15 @@ class StandaloneNewsApi(
365365
)
366366
}
367367

368+
val rawDescription = description ?: ""
369+
val summary = rawDescription.stripHtml().take(400)
370+
368371
return Pair(
369372
Entry(
370373
contentType = "html",
371374
contentSrc = "",
372-
contentText = description ?: "",
373-
summary = description,
375+
contentText = rawDescription,
376+
summary = summary,
374377
id = id,
375378
feedId = feedId,
376379
title = title ?: "",
@@ -386,10 +389,17 @@ class StandaloneNewsApi(
386389
extOpenGraphImageUrl = "",
387390
extOpenGraphImageWidth = 0,
388391
extOpenGraphImageHeight = 0,
389-
), emptyList()
392+
), links
390393
)
391394
}
392395

396+
private fun String.stripHtml(): String {
397+
return this
398+
.replace(Regex("<[^>]*>"), " ")
399+
.replace(Regex("\\s+"), " ")
400+
.trim()
401+
}
402+
393403
private fun sha256(string: String): String {
394404
val digest = MessageDigest.getInstance("SHA-256")
395405
val hash = digest.digest(string.toByteArray())

app/src/main/kotlin/org/vestifeed/db/table/Link.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class LinkQueries(private val conn: SQLiteConnection) {
4646
fun insertForFeed(feedId: String, links: List<Link>) {
4747
conn.prepare(
4848
"""
49-
INSERT INTO link (
49+
INSERT OR IGNORE INTO link (
5050
feed_id,
5151
href,
5252
rel,
@@ -78,7 +78,7 @@ class LinkQueries(private val conn: SQLiteConnection) {
7878
fun insertForEntry(entryId: String, links: List<Link>) {
7979
conn.prepare(
8080
"""
81-
INSERT INTO link (
81+
INSERT OR IGNORE INTO link (
8282
entry_id,
8383
href,
8484
rel,

0 commit comments

Comments
 (0)