Simplify default preferences handling

Closes #441
This commit is contained in:
Zed 2021-12-30 02:00:31 +01:00
parent 7590dc1cda
commit dcac7e4a26
3 changed files with 13 additions and 25 deletions

View file

@ -92,15 +92,15 @@ genPrefs:
"Autoplay gifs" "Autoplay gifs"
"Link replacements (blank to disable)": "Link replacements (blank to disable)":
replaceTwitter(input, "nitter.net"): replaceTwitter(input, ""):
"Twitter -> Nitter" "Twitter -> Nitter"
placeholder: "Nitter hostname" placeholder: "Nitter hostname"
replaceYouTube(input, "piped.kavin.rocks"): replaceYouTube(input, ""):
"YouTube -> Piped/Invidious" "YouTube -> Piped/Invidious"
placeholder: "Piped hostname" placeholder: "Piped hostname"
replaceReddit(input, "teddit.net"): replaceReddit(input, ""):
"Reddit -> Teddit/Libreddit" "Reddit -> Teddit/Libreddit"
placeholder: "Teddit hostname" placeholder: "Teddit hostname"

View file

@ -229,11 +229,6 @@ type
redisMaxConns*: int redisMaxConns*: int
redisPassword*: string redisPassword*: string
replaceTwitter*: string
replaceYouTube*: string
replaceReddit*: string
replaceInstagram*: string
Rss* = object Rss* = object
feed*, cursor*: string feed*, cursor*: string

View file

@ -1,16 +1,9 @@
#? stdtmpl(subsChar = '$', metaChar = '#') #? stdtmpl(subsChar = '$', metaChar = '#')
## SPDX-License-Identifier: AGPL-3.0-only ## SPDX-License-Identifier: AGPL-3.0-only
#import strutils, xmltree, strformat, options #import strutils, xmltree, strformat, options
#import ../types, ../utils, ../formatters #import ../types, ../utils, ../formatters, ../prefs
# #
#proc getPrefs(cfg: Config): Prefs = #proc getTitle(tweet: Tweet; retweet: string): string =
#result.replaceTwitter = cfg.replaceTwitter
#result.replaceYouTube = cfg.replaceYouTube
#result.replaceReddit = cfg.replaceReddit
#result.replaceInstagram = cfg.replaceInstagram
#end proc
#
#proc getTitle(tweet: Tweet; prefs: Prefs; retweet: string): string =
#if tweet.pinned: result = "Pinned: " #if tweet.pinned: result = "Pinned: "
#elif retweet.len > 0: result = &"RT by @{retweet}: " #elif retweet.len > 0: result = &"RT by @{retweet}: "
#elif tweet.reply.len > 0: result = &"R to @{tweet.reply[0]}: " #elif tweet.reply.len > 0: result = &"R to @{tweet.reply[0]}: "
@ -31,10 +24,10 @@
Twitter feed for: ${desc}. Generated by ${cfg.hostname} Twitter feed for: ${desc}. Generated by ${cfg.hostname}
#end proc #end proc
# #
#proc renderRssTweet(tweet: Tweet; prefs: Prefs; cfg: Config): string = #proc renderRssTweet(tweet: Tweet; cfg: Config): string =
#let tweet = tweet.retweet.get(tweet) #let tweet = tweet.retweet.get(tweet)
#let urlPrefix = getUrlPrefix(cfg) #let urlPrefix = getUrlPrefix(cfg)
#let text = replaceUrls(tweet.text, prefs, absolute=urlPrefix) #let text = replaceUrls(tweet.text, defaultPrefs, absolute=urlPrefix)
#if tweet.quote.isSome and get(tweet.quote).available: #if tweet.quote.isSome and get(tweet.quote).available:
# let quoteLink = getLink(get(tweet.quote)) # let quoteLink = getLink(get(tweet.quote))
<p>${text}<br><a href="${urlPrefix}${quoteLink}">${cfg.hostname}${quoteLink}</a></p> <p>${text}<br><a href="${urlPrefix}${quoteLink}">${cfg.hostname}${quoteLink}</a></p>
@ -60,7 +53,7 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname}
#end if #end if
#end proc #end proc
# #
#proc renderRssTweets(tweets: seq[Tweet]; prefs: Prefs; cfg: Config): string = #proc renderRssTweets(tweets: seq[Tweet]; cfg: Config): string =
#let urlPrefix = getUrlPrefix(cfg) #let urlPrefix = getUrlPrefix(cfg)
#var links: seq[string] #var links: seq[string]
#for t in tweets: #for t in tweets:
@ -71,9 +64,9 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname}
# end if # end if
# links.add link # links.add link
<item> <item>
<title>${getTitle(tweet, prefs, retweet)}</title> <title>${getTitle(tweet, retweet)}</title>
<dc:creator>@${tweet.profile.username}</dc:creator> <dc:creator>@${tweet.profile.username}</dc:creator>
<description><![CDATA[${renderRssTweet(tweet, prefs, cfg).strip(chars={'\n'})}]]></description> <description><![CDATA[${renderRssTweet(tweet, cfg).strip(chars={'\n'})}]]></description>
<pubDate>${getRfc822Time(tweet)}</pubDate> <pubDate>${getRfc822Time(tweet)}</pubDate>
<guid>${urlPrefix & link}</guid> <guid>${urlPrefix & link}</guid>
<link>${urlPrefix & link}</link> <link>${urlPrefix & link}</link>
@ -106,7 +99,7 @@ Twitter feed for: ${desc}. Generated by ${cfg.hostname}
<height>128</height> <height>128</height>
</image> </image>
#if timeline.content.len > 0: #if timeline.content.len > 0:
${renderRssTweets(timeline.content, getPrefs(cfg), cfg)} ${renderRssTweets(timeline.content, cfg)}
#end if #end if
</channel> </channel>
</rss> </rss>
@ -124,7 +117,7 @@ ${renderRssTweets(timeline.content, getPrefs(cfg), cfg)}
<description>${getDescription(list.name & " by @" & list.username, cfg)}</description> <description>${getDescription(list.name & " by @" & list.username, cfg)}</description>
<language>en-us</language> <language>en-us</language>
<ttl>40</ttl> <ttl>40</ttl>
${renderRssTweets(tweets, getPrefs(cfg), cfg)} ${renderRssTweets(tweets, cfg)}
</channel> </channel>
</rss> </rss>
#end proc #end proc
@ -142,7 +135,7 @@ ${renderRssTweets(tweets, getPrefs(cfg), cfg)}
<description>${getDescription("Search \"" & escName & "\"", cfg)}</description> <description>${getDescription("Search \"" & escName & "\"", cfg)}</description>
<language>en-us</language> <language>en-us</language>
<ttl>40</ttl> <ttl>40</ttl>
${renderRssTweets(tweets, getPrefs(cfg), cfg)} ${renderRssTweets(tweets, cfg)}
</channel> </channel>
</rss> </rss>
#end proc #end proc