nitter/src/views/rss.nimf

100 lines
3.8 KiB
Plaintext
Raw Normal View History

2019-09-15 07:57:45 +00:00
#? stdtmpl(subsChar = '$', metaChad = '#')
#import strutils, xmltree, strformat
#import ../types, ../utils, ../formatters
#const hostname {.strdefine.} = "nitter.net"
#
#proc renderRssTweet(tweet: Tweet; prefs: Prefs): string =
#let text = linkifyText(tweet.text, prefs, rss=true)
#if tweet.quote.isSome and get(tweet.quote).available:
#let quoteLink = hostname & getLink(get(tweet.quote))
<p>${text}<br><a href="https://${quoteLink}">${quoteLink}</a></p>
#else:
<p>${text}</p>
#end if
#if tweet.photos.len > 0:
<img src="https://${hostname}${getPicUrl(tweet.photos[0])}" width="250" />
#elif tweet.video.isSome:
<img src="https://${hostname}${getPicUrl(get(tweet.video).thumb)}" width="250" />
#elif tweet.gif.isSome:
#let thumb = &"https://{hostname}{getPicUrl(get(tweet.gif).thumb)}"
#let url = &"https://{hostname}{getGifUrl(get(tweet.gif).url)}"
<video poster="${thumb}" autoplay muted loop width="250">
<source src="${url}" type="video/mp4"</source></video>
#end if
#end proc
#
#proc getTitle(tweet: Tweet; prefs: Prefs): string =
#if tweet.pinned: result = "Pinned: "
#elif tweet.retweet.isSome: result = "RT: "
#end if
#result &= xmltree.escape(replaceUrl(tweet.text, prefs))
#if result.len > 0: return
#end if
#if tweet.photos.len > 0:
# result &= "Image"
#elif tweet.video.isSome:
# result &= "Video"
#elif tweet.gif.isSome:
# result &= "Gif"
#end if
#end proc
#
#proc renderTimelineRss*(tweets: seq[Tweet]; profile: Profile): string =
#let prefs = Prefs(replaceTwitter: hostname)
#result = ""
<?xml version="1.0" encoding="UTF-8"?>
2019-09-15 09:14:03 +00:00
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
2019-09-15 07:57:45 +00:00
<channel>
2019-09-15 09:14:03 +00:00
<atom:link href="https://${hostname}/${profile.username}/rss" rel="self" type="application/rss+xml" />
2019-09-15 07:57:45 +00:00
<title>${profile.fullname} / @${profile.username}</title>
2019-09-15 09:14:03 +00:00
<link>https://${hostname}/${profile.username}</link>
<description>Twitter feed for: @${profile.username}. Generated by ${hostname}</description>
2019-09-15 07:57:45 +00:00
<language>en-us</language>
<ttl>40</ttl>
<image>
2019-09-15 09:14:03 +00:00
<title>${profile.fullname} / @${profile.username}</title>
<link>https://${hostname}/${profile.username}</link>
<url>https://${hostname}${getPicUrl(profile.getUserPic(style="_400x400"))}</url>
<width>128</width>
<height>128</height>
2019-09-15 07:57:45 +00:00
</image>
#for tweet in tweets:
<item>
<title>${getTitle(tweet, prefs)}</title>
2019-09-15 09:14:03 +00:00
<dc:creator>@${tweet.profile.username}</dc:creator>
2019-09-15 07:57:45 +00:00
<description><![CDATA[${renderRssTweet(tweet, prefs).strip(chars={'\n'})}]]></description>
2019-09-15 09:14:03 +00:00
<pubDate>${getRfc822Time(tweet)}</pubDate>
2019-09-15 07:57:45 +00:00
<guid>https://${hostname}${getLink(tweet)}</guid>
<link>https://${hostname}${getLink(tweet)}</link>
</item>
#end for
</channel>
</rss>
#end proc
2019-09-20 23:08:30 +00:00
#
#proc renderListRss*(tweets: seq[Tweet]; name, list: string): string =
#let prefs = Prefs(replaceTwitter: hostname)
#result = ""
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<channel>
<atom:link href="https://${hostname}/${name}/lists/${list}/rss" rel="self" type="application/rss+xml" />
<title>${list} / @${name}</title>
<link>https://${hostname}/${name}/lists/${list}</link>
<description>Twitter feed for: ${list} by @${name}. Generated by ${hostname}</description>
<language>en-us</language>
<ttl>40</ttl>
#for tweet in tweets:
<item>
<title>${getTitle(tweet, prefs)}</title>
<dc:creator>@${tweet.profile.username}</dc:creator>
<description><![CDATA[${renderRssTweet(tweet, prefs).strip(chars={'\n'})}]]></description>
<pubDate>${getRfc822Time(tweet)}</pubDate>
<guid>https://${hostname}${getLink(tweet)}</guid>
<link>https://${hostname}${getLink(tweet)}</link>
</item>
#end for
</channel>
</rss>
#end proc