Minor code improvements
This commit is contained in:
parent
eed4d4033f
commit
d96550fcce
5 changed files with 17 additions and 12 deletions
|
@ -28,7 +28,7 @@ const
|
||||||
twitter = parseUri("https://twitter.com")
|
twitter = parseUri("https://twitter.com")
|
||||||
|
|
||||||
proc getUrlPrefix*(cfg: Config): string =
|
proc getUrlPrefix*(cfg: Config): string =
|
||||||
if cfg.useHttps: "https://" & cfg.hostname
|
if cfg.useHttps: https & cfg.hostname
|
||||||
else: "http://" & cfg.hostname
|
else: "http://" & cfg.hostname
|
||||||
|
|
||||||
proc stripHtml*(text: string): string =
|
proc stripHtml*(text: string): string =
|
||||||
|
@ -58,7 +58,7 @@ proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string =
|
||||||
|
|
||||||
if prefs.replaceTwitter.len > 0 and
|
if prefs.replaceTwitter.len > 0 and
|
||||||
(twRegex in result or tco in result):
|
(twRegex in result or tco in result):
|
||||||
result = result.replace(tco, "https://" & prefs.replaceTwitter & "/t.co")
|
result = result.replace(tco, https & prefs.replaceTwitter & "/t.co")
|
||||||
result = result.replace(cards, prefs.replaceTwitter & "/cards")
|
result = result.replace(cards, prefs.replaceTwitter & "/cards")
|
||||||
result = result.replace(twRegex, prefs.replaceTwitter)
|
result = result.replace(twRegex, prefs.replaceTwitter)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import strutils, uri
|
||||||
import jester
|
import jester
|
||||||
|
|
||||||
import router_utils
|
import router_utils
|
||||||
import ".."/[query, types, api]
|
import ".."/[query, types, api, formatters]
|
||||||
import ../views/[general, search]
|
import ../views/[general, search]
|
||||||
|
|
||||||
include "../views/opensearch.nimf"
|
include "../views/opensearch.nimf"
|
||||||
|
@ -40,7 +40,6 @@ proc createSearchRouter*(cfg: Config) =
|
||||||
redirect("/search?q=" & encodeUrl("#" & @"hash"))
|
redirect("/search?q=" & encodeUrl("#" & @"hash"))
|
||||||
|
|
||||||
get "/opensearch":
|
get "/opensearch":
|
||||||
var url = if cfg.useHttps: "https://" else: "http://"
|
let url = getUrlPrefix(cfg) & "/search?q="
|
||||||
url &= cfg.hostname & "/search?q="
|
|
||||||
resp Http200, {"Content-Type": "application/opensearchdescription+xml"},
|
resp Http200, {"Content-Type": "application/opensearchdescription+xml"},
|
||||||
generateOpenSearchXML(cfg.title, cfg.hostname, url)
|
generateOpenSearchXML(cfg.title, cfg.hostname, url)
|
||||||
|
|
|
@ -18,6 +18,7 @@ proc createStatusRouter*(cfg: Config) =
|
||||||
cond '.' notin @"name"
|
cond '.' notin @"name"
|
||||||
let prefs = cookiePrefs()
|
let prefs = cookiePrefs()
|
||||||
|
|
||||||
|
# used for the infinite scroll feature
|
||||||
if @"scroll".len > 0:
|
if @"scroll".len > 0:
|
||||||
let replies = await getReplies(@"id", getCursor())
|
let replies = await getReplies(@"id", getCursor())
|
||||||
if replies.content.len == 0:
|
if replies.content.len == 0:
|
||||||
|
@ -34,10 +35,12 @@ proc createStatusRouter*(cfg: Config) =
|
||||||
error = conv.tweet.tombstone
|
error = conv.tweet.tombstone
|
||||||
resp Http404, showError(error, cfg)
|
resp Http404, showError(error, cfg)
|
||||||
|
|
||||||
var
|
let
|
||||||
title = pageTitle(conv.tweet)
|
title = pageTitle(conv.tweet)
|
||||||
ogTitle = pageTitle(conv.tweet.profile)
|
ogTitle = pageTitle(conv.tweet.profile)
|
||||||
desc = conv.tweet.text
|
desc = conv.tweet.text
|
||||||
|
|
||||||
|
var
|
||||||
images = conv.tweet.photos
|
images = conv.tweet.photos
|
||||||
video = ""
|
video = ""
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,7 @@ proc createTimelineRouter*(cfg: Config) =
|
||||||
if names.len != 1:
|
if names.len != 1:
|
||||||
query.fromUser = names
|
query.fromUser = names
|
||||||
|
|
||||||
|
# used for the infinite scroll feature
|
||||||
if @"scroll".len > 0:
|
if @"scroll".len > 0:
|
||||||
if query.fromUser.len != 1:
|
if query.fromUser.len != 1:
|
||||||
var timeline = await getSearch[Tweet](query, after)
|
var timeline = await getSearch[Tweet](query, after)
|
||||||
|
@ -143,10 +144,12 @@ proc createTimelineRouter*(cfg: Config) =
|
||||||
timeline.beginning = true
|
timeline.beginning = true
|
||||||
resp $renderTimelineTweets(timeline, prefs, getPath())
|
resp $renderTimelineTweets(timeline, prefs, getPath())
|
||||||
|
|
||||||
var rss = "/$1/$2/rss" % [@"name", @"tab"]
|
let rss =
|
||||||
if @"tab".len == 0:
|
if @"tab".len == 0:
|
||||||
rss = "/$1/rss" % @"name"
|
"/$1/rss" % @"name"
|
||||||
elif @"tab" == "search":
|
elif @"tab" == "search":
|
||||||
rss &= "?" & genQueryUrl(query)
|
"/$1/search/rss?$2" % [@"name", genQueryUrl(query)]
|
||||||
|
else:
|
||||||
|
"/$1/$2/rss" % [@"name", @"tab"]
|
||||||
|
|
||||||
respTimeline(await showTimeline(request, query, cfg, prefs, rss, after))
|
respTimeline(await showTimeline(request, query, cfg, prefs, rss, after))
|
||||||
|
|
|
@ -31,7 +31,7 @@ proc linkUser*(profile: Profile, class=""): VNode =
|
||||||
icon "lock", title="Protected account"
|
icon "lock", title="Protected account"
|
||||||
|
|
||||||
proc linkText*(text: string; class=""): VNode =
|
proc linkText*(text: string; class=""): VNode =
|
||||||
let url = if "http" notin text: "http://" & text else: text
|
let url = if "http" notin text: https & text else: text
|
||||||
buildHtml():
|
buildHtml():
|
||||||
a(href=url, class=class): text text
|
a(href=url, class=class): text text
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue