| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #? stdtmpl(subsChar = '$', metaChad = '#')
- #import strutils, xmltree, strformat, options
- #import ../types, ../utils, ../formatters
- #
- #proc getTitle(tweet: Tweet; prefs: Prefs; hostname: string): string =
- #if tweet.pinned: result = "Pinned: "
- #elif tweet.retweet.isSome: result = "RT: "
- #elif tweet.reply.len > 0: result = "R: "
- #end if
- #result &= xmltree.escape(stripHtml(tweet.text))
- #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 renderRssTweet(tweet: Tweet; prefs: Prefs; hostname: string): string =
- #let text = replaceUrl(tweet.text, prefs, absolute=hostname)
- #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:
- #for photo in tweet.photos:
- <img src="https://${hostname}${getPicUrl(photo)}" style="max-width:250px;" />
- #end for
- #elif tweet.video.isSome:
- <img src="https://${hostname}${getPicUrl(get(tweet.video).thumb)}" style="max-width:250px;" />
- #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 style="max-width:250px;">
- <source src="${url}" type="video/mp4"</source></video>
- #end if
- #end proc
- #
- #proc renderRssTweets(tweets: seq[Tweet]; prefs: Prefs; hostname: string): string =
- #var links: seq[string]
- #for tweet in tweets:
- #let link = getLink(tweet)
- #if link in links: continue
- #end if
- #links.add link
- <item>
- <title>${getTitle(tweet, prefs, hostname)}</title>
- <dc:creator>@${tweet.profile.username}</dc:creator>
- <description><![CDATA[${renderRssTweet(tweet, prefs, hostname).strip(chars={'\n'})}]]></description>
- <pubDate>${getRfc822Time(tweet)}</pubDate>
- <guid>https://${hostname & link}</guid>
- <link>https://${hostname & link}</link>
- </item>
- #end for
- #end proc
- #
- #proc renderTimelineRss*(timeline: Timeline; profile: Profile; hostname: string; multi=false): string =
- #let prefs = Prefs(replaceTwitter: hostname, replaceYouTube: "invidio.us")
- #result = ""
- #let user = (if multi: "" else: "@") & profile.username
- #var title = profile.fullname
- #if not multi: title &= " / " & user
- #end if
- <?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}/${profile.username}/rss" rel="self" type="application/rss+xml" />
- <title>${title}</title>
- <link>https://${hostname}/${profile.username}</link>
- <description>Twitter feed for: ${user}. Generated by ${hostname}</description>
- <language>en-us</language>
- <ttl>40</ttl>
- <image>
- <title>${title}</title>
- <link>https://${hostname}/${profile.username}</link>
- <url>https://${hostname}${getPicUrl(profile.getUserPic(style="_400x400"))}</url>
- <width>128</width>
- <height>128</height>
- </image>
- #if timeline != nil:
- ${renderRssTweets(timeline.content, prefs, hostname)}
- #end if
- </channel>
- </rss>
- #end proc
- #
- #proc renderListRss*(tweets: seq[Tweet]; name, list, hostname: string): string =
- #let prefs = Prefs(replaceTwitter: hostname, replaceYouTube: "invidio.us")
- #let link = &"https://{hostname}/{name}/lists/{list}"
- #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>${list} / @${name}</title>
- <link>${link}</link>
- <description>Twitter feed for: ${list} by @${name}. Generated by ${hostname}</description>
- <language>en-us</language>
- <ttl>40</ttl>
- ${renderRssTweets(tweets, prefs, hostname)}
- </channel>
- </rss>
- #end proc
- #
- #proc renderSearchRss*(tweets: seq[Tweet]; name, param, hostname: string): string =
- #let prefs = Prefs(replaceTwitter: hostname, replaceYouTube: "invidio.us")
- #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>
- ${renderRssTweets(tweets, prefs, hostname)}
- </channel>
- </rss>
- #end proc
|