2021-12-27 01:43:27 +00:00
|
|
|
#? stdtmpl(subsChar = '$', metaChar = '#')
|
|
|
|
## SPDX-License-Identifier: AGPL-3.0-only
|
2021-07-21 22:57:13 +00:00
|
|
|
#import strutils, xmltree, strformat, options, unicode
|
2021-12-30 01:00:31 +00:00
|
|
|
#import ../types, ../utils, ../formatters, ../prefs
|
2019-09-15 07:57:45 +00:00
|
|
|
#
|
2021-12-30 01:00:31 +00:00
|
|
|
#proc getTitle(tweet: Tweet; retweet: string): string =
|
2019-09-28 01:22:46 +00:00
|
|
|
#if tweet.pinned: result = "Pinned: "
|
2020-06-10 15:52:21 +00:00
|
|
|
#elif retweet.len > 0: result = &"RT by @{retweet}: "
|
|
|
|
#elif tweet.reply.len > 0: result = &"R to @{tweet.reply[0]}: "
|
2019-09-28 01:22:46 +00:00
|
|
|
#end if
|
2021-07-21 22:57:13 +00:00
|
|
|
#var text = stripHtml(tweet.text)
|
2021-12-31 12:30:19 +00:00
|
|
|
##if unicode.runeLen(text) > 32:
|
|
|
|
## text = unicode.runeSubStr(text, 0, 32) & "..."
|
|
|
|
##end if
|
2021-07-21 22:57:13 +00:00
|
|
|
#result &= xmltree.escape(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
|
|
|
|
#
|
2021-01-08 01:25:43 +00:00
|
|
|
#proc getDescription(desc: string; cfg: Config): string =
|
|
|
|
Twitter feed for: ${desc}. Generated by ${cfg.hostname}
|
|
|
|
#end proc
|
|
|
|
#
|
2021-12-30 01:00:31 +00:00
|
|
|
#proc renderRssTweet(tweet: Tweet; cfg: Config): string =
|
2020-06-01 03:50:59 +00:00
|
|
|
#let tweet = tweet.retweet.get(tweet)
|
2021-01-08 01:25:43 +00:00
|
|
|
#let urlPrefix = getUrlPrefix(cfg)
|
2021-12-30 01:00:31 +00:00
|
|
|
#let text = replaceUrls(tweet.text, defaultPrefs, absolute=urlPrefix)
|
2021-07-06 02:56:44 +00:00
|
|
|
<p>${text.replace("\n", "<br>\n")}</p>
|
2019-09-15 07:57:45 +00:00
|
|
|
#if tweet.quote.isSome and get(tweet.quote).available:
|
2021-01-08 01:25:43 +00:00
|
|
|
# let quoteLink = getLink(get(tweet.quote))
|
2021-07-06 02:56:44 +00:00
|
|
|
<p><a href="${urlPrefix}${quoteLink}">${cfg.hostname}${quoteLink}</a></p>
|
2019-09-15 07:57:45 +00:00
|
|
|
#end if
|
|
|
|
#if tweet.photos.len > 0:
|
2021-01-08 01:25:43 +00:00
|
|
|
# for photo in tweet.photos:
|
|
|
|
<img src="${urlPrefix}${getPicUrl(photo)}" style="max-width:250px;" />
|
|
|
|
# end for
|
2019-09-15 07:57:45 +00:00
|
|
|
#elif tweet.video.isSome:
|
2021-01-08 01:25:43 +00:00
|
|
|
<img src="${urlPrefix}${getPicUrl(get(tweet.video).thumb)}" style="max-width:250px;" />
|
2019-09-15 07:57:45 +00:00
|
|
|
#elif tweet.gif.isSome:
|
2021-01-08 01:25:43 +00:00
|
|
|
# let thumb = &"{urlPrefix}{getPicUrl(get(tweet.gif).thumb)}"
|
|
|
|
# let url = &"{urlPrefix}{getPicUrl(get(tweet.gif).url)}"
|
2020-03-09 01:02:16 +00:00
|
|
|
<video poster="${thumb}" autoplay muted loop style="max-width:250px;">
|
2022-02-11 07:50:32 +00:00
|
|
|
<source src="${url}" type="video/mp4"></video>
|
2021-09-28 07:27:13 +00:00
|
|
|
#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
|
2019-09-15 07:57:45 +00:00
|
|
|
#end if
|
|
|
|
#end proc
|
|
|
|
#
|
2021-12-30 01:00:31 +00:00
|
|
|
#proc renderRssTweets(tweets: seq[Tweet]; cfg: Config): string =
|
2021-01-08 01:25:43 +00:00
|
|
|
#let urlPrefix = getUrlPrefix(cfg)
|
2019-09-28 01:22:46 +00:00
|
|
|
#var links: seq[string]
|
2020-06-01 03:50:59 +00:00
|
|
|
#for t in tweets:
|
2022-01-23 06:04:50 +00:00
|
|
|
# let retweet = if t.retweet.isSome: t.user.username else: ""
|
2021-01-08 01:25:43 +00:00
|
|
|
# let tweet = if retweet.len > 0: t.retweet.get else: t
|
|
|
|
# let link = getLink(tweet)
|
|
|
|
# if link in links: continue
|
|
|
|
# end if
|
|
|
|
# links.add link
|
|
|
|
<item>
|
2021-12-30 01:00:31 +00:00
|
|
|
<title>${getTitle(tweet, retweet)}</title>
|
2022-01-23 06:04:50 +00:00
|
|
|
<dc:creator>@${tweet.user.username}</dc:creator>
|
2021-12-30 01:00:31 +00:00
|
|
|
<description><![CDATA[${renderRssTweet(tweet, cfg).strip(chars={'\n'})}]]></description>
|
2021-01-08 01:25:43 +00:00
|
|
|
<pubDate>${getRfc822Time(tweet)}</pubDate>
|
|
|
|
<guid>${urlPrefix & link}</guid>
|
|
|
|
<link>${urlPrefix & link}</link>
|
|
|
|
</item>
|
2019-09-28 01:22:46 +00:00
|
|
|
#end for
|
2019-09-15 07:57:45 +00:00
|
|
|
#end proc
|
|
|
|
#
|
2022-01-23 06:04:50 +00:00
|
|
|
#proc renderTimelineRss*(profile: Profile; cfg: Config; multi=false): string =
|
2021-01-08 01:25:43 +00:00
|
|
|
#let urlPrefix = getUrlPrefix(cfg)
|
2019-09-15 07:57:45 +00:00
|
|
|
#result = ""
|
2022-01-23 06:04:50 +00:00
|
|
|
#let handle = (if multi: "" else: "@") & profile.user.username
|
|
|
|
#var title = profile.user.fullname
|
|
|
|
#if not multi: title &= " / " & handle
|
2019-12-04 04:58:18 +00:00
|
|
|
#end if
|
2020-11-07 22:53:49 +00:00
|
|
|
#title = xmltree.escape(title).sanitizeXml
|
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>
|
2022-01-23 06:04:50 +00:00
|
|
|
<atom:link href="${urlPrefix}/${profile.user.username}/rss" rel="self" type="application/rss+xml" />
|
2019-12-04 04:58:18 +00:00
|
|
|
<title>${title}</title>
|
2022-01-23 06:04:50 +00:00
|
|
|
<link>${urlPrefix}/${profile.user.username}</link>
|
|
|
|
<description>${getDescription(handle, cfg)}</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>
|
2022-01-23 06:04:50 +00:00
|
|
|
<link>${urlPrefix}/${profile.user.username}</link>
|
|
|
|
<url>${urlPrefix}${getPicUrl(profile.user.getUserPic(style="_400x400"))}</url>
|
2019-09-15 09:14:03 +00:00
|
|
|
<width>128</width>
|
|
|
|
<height>128</height>
|
2019-09-15 07:57:45 +00:00
|
|
|
</image>
|
2022-01-23 06:04:50 +00:00
|
|
|
#if profile.tweets.content.len > 0:
|
|
|
|
${renderRssTweets(profile.tweets.content, cfg)}
|
2021-01-08 01:25:43 +00:00
|
|
|
#end if
|
2019-09-15 07:57:45 +00:00
|
|
|
</channel>
|
|
|
|
</rss>
|
|
|
|
#end proc
|
2019-09-20 23:08:30 +00:00
|
|
|
#
|
2021-01-08 01:25:43 +00:00
|
|
|
#proc renderListRss*(tweets: seq[Tweet]; list: List; cfg: Config): string =
|
2021-10-02 08:13:56 +00:00
|
|
|
#let link = &"{getUrlPrefix(cfg)}/i/lists/{list.id}"
|
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" />
|
2020-06-10 15:17:17 +00:00
|
|
|
<title>${xmltree.escape(list.name)} / @${list.username}</title>
|
2019-09-28 01:22:46 +00:00
|
|
|
<link>${link}</link>
|
2022-06-04 00:18:26 +00:00
|
|
|
<description>${getDescription(&"{list.name} by @{list.username}", cfg)}</description>
|
2019-09-20 23:08:30 +00:00
|
|
|
<language>en-us</language>
|
|
|
|
<ttl>40</ttl>
|
2021-12-30 01:00:31 +00:00
|
|
|
${renderRssTweets(tweets, cfg)}
|
2019-09-28 01:22:46 +00:00
|
|
|
</channel>
|
|
|
|
</rss>
|
|
|
|
#end proc
|
|
|
|
#
|
2021-01-08 01:25:43 +00:00
|
|
|
#proc renderSearchRss*(tweets: seq[Tweet]; name, param: string; cfg: Config): string =
|
|
|
|
#let link = &"{getUrlPrefix(cfg)}/search"
|
2020-06-10 15:17:17 +00:00
|
|
|
#let escName = xmltree.escape(name)
|
2019-09-28 01:22:46 +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>
|
|
|
|
<atom:link href="${link}" rel="self" type="application/rss+xml" />
|
2020-06-10 15:17:17 +00:00
|
|
|
<title>Search results for "${escName}"</title>
|
2019-09-28 01:22:46 +00:00
|
|
|
<link>${link}</link>
|
2022-06-04 00:18:26 +00:00
|
|
|
<description>${getDescription(&"Search \"{escName}\"", cfg)}</description>
|
2019-09-28 01:22:46 +00:00
|
|
|
<language>en-us</language>
|
|
|
|
<ttl>40</ttl>
|
2021-12-30 01:00:31 +00:00
|
|
|
${renderRssTweets(tweets, cfg)}
|
2019-09-20 23:08:30 +00:00
|
|
|
</channel>
|
|
|
|
</rss>
|
|
|
|
#end proc
|