2019-09-15 07:57:45 +00:00
|
|
|
#? stdtmpl(subsChar = '$', metaChad = '#')
|
2019-10-26 13:34:30 +00:00
|
|
|
#import strutils, xmltree, strformat, options
|
2019-09-15 07:57:45 +00:00
|
|
|
#import ../types, ../utils, ../formatters
|
|
|
|
#
|
2019-10-21 03:19:00 +00:00
|
|
|
#proc getTitle(tweet: Tweet; prefs: Prefs; hostname: string): string =
|
2019-09-28 01:22:46 +00:00
|
|
|
#if tweet.pinned: result = "Pinned: "
|
|
|
|
#elif tweet.retweet.isSome: result = "RT: "
|
2020-03-29 06:06:20 +00:00
|
|
|
#elif tweet.reply.len > 0: result = "R: "
|
2019-09-28 01:22:46 +00:00
|
|
|
#end if
|
2019-10-21 03:31:12 +00:00
|
|
|
#result &= xmltree.escape(stripHtml(tweet.text))
|
2019-09-28 01:22:46 +00:00
|
|
|
#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
|
|
|
|
#
|
2019-10-21 03:19:00 +00:00
|
|
|
#proc renderRssTweet(tweet: Tweet; prefs: Prefs; hostname: string): string =
|
|
|
|
#let text = replaceUrl(tweet.text, prefs, absolute=hostname)
|
2019-09-15 07:57:45 +00:00
|
|
|
#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:
|
2019-12-06 00:33:26 +00:00
|
|
|
#for photo in tweet.photos:
|
2020-03-09 01:02:16 +00:00
|
|
|
<img src="https://${hostname}${getPicUrl(photo)}" style="max-width:250px;" />
|
2019-12-06 00:33:26 +00:00
|
|
|
#end for
|
2019-09-15 07:57:45 +00:00
|
|
|
#elif tweet.video.isSome:
|
2020-03-09 01:02:16 +00:00
|
|
|
<img src="https://${hostname}${getPicUrl(get(tweet.video).thumb)}" style="max-width:250px;" />
|
2019-09-15 07:57:45 +00:00
|
|
|
#elif tweet.gif.isSome:
|
|
|
|
#let thumb = &"https://{hostname}{getPicUrl(get(tweet.gif).thumb)}"
|
|
|
|
#let url = &"https://{hostname}{getGifUrl(get(tweet.gif).url)}"
|
2020-03-09 01:02:16 +00:00
|
|
|
<video poster="${thumb}" autoplay muted loop style="max-width:250px;">
|
2019-09-15 07:57:45 +00:00
|
|
|
<source src="${url}" type="video/mp4"</source></video>
|
|
|
|
#end if
|
|
|
|
#end proc
|
|
|
|
#
|
2019-10-21 03:19:00 +00:00
|
|
|
#proc renderRssTweets(tweets: seq[Tweet]; prefs: Prefs; hostname: string): string =
|
2019-09-28 01:22:46 +00:00
|
|
|
#var links: seq[string]
|
|
|
|
#for tweet in tweets:
|
|
|
|
#let link = getLink(tweet)
|
|
|
|
#if link in links: continue
|
2019-09-15 07:57:45 +00:00
|
|
|
#end if
|
2019-09-28 01:22:46 +00:00
|
|
|
#links.add link
|
|
|
|
<item>
|
2019-10-21 03:19:00 +00:00
|
|
|
<title>${getTitle(tweet, prefs, hostname)}</title>
|
2019-09-28 01:22:46 +00:00
|
|
|
<dc:creator>@${tweet.profile.username}</dc:creator>
|
2019-10-21 03:19:00 +00:00
|
|
|
<description><![CDATA[${renderRssTweet(tweet, prefs, hostname).strip(chars={'\n'})}]]></description>
|
2019-09-28 01:22:46 +00:00
|
|
|
<pubDate>${getRfc822Time(tweet)}</pubDate>
|
|
|
|
<guid>https://${hostname & link}</guid>
|
|
|
|
<link>https://${hostname & link}</link>
|
|
|
|
</item>
|
|
|
|
#end for
|
2019-09-15 07:57:45 +00:00
|
|
|
#end proc
|
|
|
|
#
|
2019-12-04 04:58:18 +00:00
|
|
|
#proc renderTimelineRss*(timeline: Timeline; profile: Profile; hostname: string; multi=false): string =
|
2019-10-09 14:06:51 +00:00
|
|
|
#let prefs = Prefs(replaceTwitter: hostname, replaceYoutube: "invidio.us")
|
2019-09-15 07:57:45 +00:00
|
|
|
#result = ""
|
2019-12-04 04:58:18 +00:00
|
|
|
#let user = (if multi: "" else: "@") & profile.username
|
|
|
|
#var title = profile.fullname
|
|
|
|
#if not multi: title &= " / " & user
|
|
|
|
#end if
|
2019-09-15 07:57:45 +00:00
|
|
|
<?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-12-04 04:58:18 +00:00
|
|
|
<title>${title}</title>
|
2019-09-15 09:14:03 +00:00
|
|
|
<link>https://${hostname}/${profile.username}</link>
|
2019-12-04 04:58:18 +00:00
|
|
|
<description>Twitter feed for: ${user}. Generated by ${hostname}</description>
|
2019-09-15 07:57:45 +00:00
|
|
|
<language>en-us</language>
|
|
|
|
<ttl>40</ttl>
|
|
|
|
<image>
|
2019-12-04 04:58:18 +00:00
|
|
|
<title>${title}</title>
|
2019-09-15 09:14:03 +00:00
|
|
|
<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>
|
2019-10-07 13:52:44 +00:00
|
|
|
#if timeline != nil:
|
2019-10-21 03:19:00 +00:00
|
|
|
${renderRssTweets(timeline.content, prefs, hostname)}
|
2019-10-07 13:52:44 +00:00
|
|
|
#end if
|
2019-09-15 07:57:45 +00:00
|
|
|
</channel>
|
|
|
|
</rss>
|
|
|
|
#end proc
|
2019-09-20 23:08:30 +00:00
|
|
|
#
|
2019-10-21 03:19:00 +00:00
|
|
|
#proc renderListRss*(tweets: seq[Tweet]; name, list, hostname: string): string =
|
2019-10-09 14:06:51 +00:00
|
|
|
#let prefs = Prefs(replaceTwitter: hostname, replaceYoutube: "invidio.us")
|
2019-09-28 01:22:46 +00:00
|
|
|
#let link = &"https://{hostname}/{name}/lists/{list}"
|
2019-09-20 23:08:30 +00:00
|
|
|
#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>
|
2019-09-28 01:22:46 +00:00
|
|
|
<atom:link href="${link}" rel="self" type="application/rss+xml" />
|
2019-09-20 23:08:30 +00:00
|
|
|
<title>${list} / @${name}</title>
|
2019-09-28 01:22:46 +00:00
|
|
|
<link>${link}</link>
|
2019-09-20 23:08:30 +00:00
|
|
|
<description>Twitter feed for: ${list} by @${name}. Generated by ${hostname}</description>
|
|
|
|
<language>en-us</language>
|
|
|
|
<ttl>40</ttl>
|
2019-10-21 03:19:00 +00:00
|
|
|
${renderRssTweets(tweets, prefs, hostname)}
|
2019-09-28 01:22:46 +00:00
|
|
|
</channel>
|
|
|
|
</rss>
|
|
|
|
#end proc
|
|
|
|
#
|
2019-10-21 03:19:00 +00:00
|
|
|
#proc renderSearchRss*(tweets: seq[Tweet]; name, param, hostname: string): string =
|
2019-10-09 14:06:51 +00:00
|
|
|
#let prefs = Prefs(replaceTwitter: hostname, replaceYoutube: "invidio.us")
|
2019-09-28 01:22:46 +00:00
|
|
|
#let link = &"https://{hostname}/search"
|
|
|
|
#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="${link}" rel="self" type="application/rss+xml" />
|
|
|
|
<title>Search results for "${name}"</title>
|
|
|
|
<link>${link}</link>
|
|
|
|
<description>Twitter feed for search "${name}". Generated by ${hostname}</description>
|
|
|
|
<language>en-us</language>
|
|
|
|
<ttl>40</ttl>
|
2019-10-21 03:19:00 +00:00
|
|
|
${renderRssTweets(tweets, prefs, hostname)}
|
2019-09-20 23:08:30 +00:00
|
|
|
</channel>
|
|
|
|
</rss>
|
|
|
|
#end proc
|