Skip to content

Commit

Permalink
Minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
zedeus committed Dec 30, 2021
1 parent eed4d40 commit d96550f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/formatters.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const
twitter = parseUri("https://twitter.com")

proc getUrlPrefix*(cfg: Config): string =
if cfg.useHttps: "https://" & cfg.hostname
if cfg.useHttps: https & cfg.hostname
else: "http://" & cfg.hostname

proc stripHtml*(text: string): string =
Expand Down Expand Up @@ -58,7 +58,7 @@ proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string =

if prefs.replaceTwitter.len > 0 and
(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(twRegex, prefs.replaceTwitter)

Expand Down
5 changes: 2 additions & 3 deletions src/routes/search.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import strutils, uri
import jester

import router_utils
import ".."/[query, types, api]
import ".."/[query, types, api, formatters]
import ../views/[general, search]

include "../views/opensearch.nimf"
Expand Down Expand Up @@ -40,7 +40,6 @@ proc createSearchRouter*(cfg: Config) =
redirect("/search?q=" & encodeUrl("#" & @"hash"))

get "/opensearch":
var url = if cfg.useHttps: "https://" else: "http://"
url &= cfg.hostname & "/search?q="
let url = getUrlPrefix(cfg) & "/search?q="
resp Http200, {"Content-Type": "application/opensearchdescription+xml"},
generateOpenSearchXML(cfg.title, cfg.hostname, url)
5 changes: 4 additions & 1 deletion src/routes/status.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ proc createStatusRouter*(cfg: Config) =
cond '.' notin @"name"
let prefs = cookiePrefs()

# used for the infinite scroll feature
if @"scroll".len > 0:
let replies = await getReplies(@"id", getCursor())
if replies.content.len == 0:
Expand All @@ -34,10 +35,12 @@ proc createStatusRouter*(cfg: Config) =
error = conv.tweet.tombstone
resp Http404, showError(error, cfg)

var
let
title = pageTitle(conv.tweet)
ogTitle = pageTitle(conv.tweet.profile)
desc = conv.tweet.text

var
images = conv.tweet.photos
video = ""

Expand Down
13 changes: 8 additions & 5 deletions src/routes/timeline.nim
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ proc createTimelineRouter*(cfg: Config) =
if names.len != 1:
query.fromUser = names

# used for the infinite scroll feature
if @"scroll".len > 0:
if query.fromUser.len != 1:
var timeline = await getSearch[Tweet](query, after)
Expand All @@ -143,10 +144,12 @@ proc createTimelineRouter*(cfg: Config) =
timeline.beginning = true
resp $renderTimelineTweets(timeline, prefs, getPath())

var rss = "/$1/$2/rss" % [@"name", @"tab"]
if @"tab".len == 0:
rss = "/$1/rss" % @"name"
elif @"tab" == "search":
rss &= "?" & genQueryUrl(query)
let rss =
if @"tab".len == 0:
"/$1/rss" % @"name"
elif @"tab" == "search":
"/$1/search/rss?$2" % [@"name", genQueryUrl(query)]
else:
"/$1/$2/rss" % [@"name", @"tab"]

respTimeline(await showTimeline(request, query, cfg, prefs, rss, after))
2 changes: 1 addition & 1 deletion src/views/renderutils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ proc linkUser*(profile: Profile, class=""): VNode =
icon "lock", title="Protected account"

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():
a(href=url, class=class): text text

Expand Down

0 comments on commit d96550f

Please sign in to comment.