Преглед изворни кода

Add link preview text to RSS feed

Fixes #679
Zed пре 2 месеци
родитељ
комит
c136e47748
1 измењених фајлова са 34 додато и 5 уклоњено
  1. 34 5
      src/views/rss.nimf

+ 34 - 5
src/views/rss.nimf

@@ -34,6 +34,12 @@
 #    end case
 #  end if
 #end if
+#if result.len == 0 and tweet.card.isSome:
+#  let card = tweet.card.get()
+#  if card.kind notin {hidden, unknown} and card.title.len > 0:
+#    result = prefix & xmltree.escape(card.title)
+#  end if
+#end if
 #end proc
 #
 #proc getDescription(desc: string; cfg: Config): string =
@@ -60,6 +66,32 @@ Twitter feed for: ${desc}. Generated by ${getUrlPrefix(cfg)}
 #end case
 #end proc
 #
+#proc renderRssCard(card: Card; prefs: Prefs; urlPrefix: string): string =
+#let cardLink = if card.url.startsWith("/"): urlPrefix & card.url else: replaceUrls(card.url, prefs)
+#let title = xmltree.escape(card.title)
+#if cardLink.len > 0:
+<a href="${xmltree.escape(cardLink)}">
+#end if
+#if card.image.len > 0:
+<img src="${urlPrefix}${getPicUrl(card.image)}" style="max-width:250px;" />
+#end if
+#if title.len > 0:
+#  if card.image.len > 0:
+<br>
+#  end if
+<b>${title}</b>
+#end if
+#if cardLink.len > 0:
+</a>
+#end if
+#if card.text.len > 0:
+<p>${xmltree.escape(card.text)}</p>
+#end if
+#if card.dest.len > 0:
+<small>${xmltree.escape(card.dest)}</small>
+#end if
+#end proc
+#
 #proc getTweetsWithPinned(profile: Profile): seq[Tweets] =
 #result = profile.tweets.content
 #if profile.pinned.isSome and result.len > 0:
@@ -87,11 +119,8 @@ Twitter feed for: ${desc}. Generated by ${getUrlPrefix(cfg)}
 #  for media in tweet.media:
 ${renderRssMedia(media, tweet, urlPrefix)}
 #  end for
-#elif tweet.card.isSome:
-#  let card = tweet.card.get()
-#  if card.image.len > 0:
-<img src="${urlPrefix}${getPicUrl(card.image)}" style="max-width:250px;" />
-#  end if
+#elif tweet.card.isSome and tweet.card.get().kind notin {hidden, unknown}:
+${renderRssCard(tweet.card.get(), prefs, urlPrefix)}
 #end if
 #if tweet.note.len > 0 and not prefs.hideCommunityNotes:
 <p><b>Community note:</b> ${replaceUrls(tweet.note, prefs, absolute=urlPrefix)}</p>