From 875a2c538796924e7cd8e03aff9b0930aac42178 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 19:34:10 +0200 Subject: [PATCH] moved themes to be handled in renderHead and changed path to /embed --- src/routes/embed.nim | 11 +++++++---- src/views/embed.nim | 5 +++-- src/views/general.nim | 18 +++++++++++------- src/views/tweet.nim | 5 +++-- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/routes/embed.nim b/src/routes/embed.nim index 9a4c85b..2db9a41 100644 --- a/src/routes/embed.nim +++ b/src/routes/embed.nim @@ -15,12 +15,15 @@ proc createEmbedRouter*(cfg: Config) = if convo == nil or convo.tweet == nil or convo.tweet.video.isNone: resp Http404 - resp renderVideoEmbed(cfg, convo.tweet) + resp renderVideoEmbed(cfg, request, convo.tweet) - get "/@user/status/@id/embedded": + get "/@user/status/@id/embed": let - tweet = (await getTweet(@"id")).tweet + convo = await getTweet(@"id") prefs = cookiePrefs() path = getPath() - resp $renderEmbeddedTweet(tweet, cfg, prefs, path) + if convo == nil or convo.tweet == nil: + resp Http404 + + resp $renderEmbeddedTweet(convo.tweet, cfg, request, prefs, path) diff --git a/src/views/embed.nim b/src/views/embed.nim index 4c2f7b3..edce944 100644 --- a/src/views/embed.nim +++ b/src/views/embed.nim @@ -1,18 +1,19 @@ # SPDX-License-Identifier: AGPL-3.0-only import options import karax/[karaxdsl, vdom] +from jester import Request import ".."/[types, formatters] import general, tweet const doctype = "\n" -proc renderVideoEmbed*(cfg: Config; tweet: Tweet): string = +proc renderVideoEmbed*(cfg: Config; req: Request; tweet: Tweet): string = let thumb = get(tweet.video).thumb let vidUrl = getVideoEmbed(cfg, tweet.id) let prefs = Prefs(hlsPlayback: true) let node = buildHtml(html(lang="en")): - renderHead(prefs, cfg, video=vidUrl, images=(@[thumb])) + renderHead(prefs, cfg, req, video=vidUrl, images=(@[thumb])) tdiv(class="embed-video"): renderVideo(get(tweet.video), prefs, "") diff --git a/src/views/general.nim b/src/views/general.nim index 4a8b4a3..e514ab8 100644 --- a/src/views/general.nim +++ b/src/views/general.nim @@ -11,6 +11,9 @@ const doctype = "\n" lp = readFile("public/lp.svg") +proc toTheme(theme: string): string = + theme.toLowerAscii.replace(" ", "_") + proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode = var path = req.params.getOrDefault("referer") if path.len == 0: @@ -33,9 +36,13 @@ proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode = icon "info", title="About", href="/about" icon "cog", title="Preferences", href=("/settings?referer=" & encodeUrl(path)) -proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video=""; - images: seq[string] = @[]; banner=""; ogTitle=""; theme=""; +proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc=""; + video=""; images: seq[string] = @[]; banner=""; ogTitle=""; rss=""; canonical=""): VNode = + var theme = prefs.theme.toTheme + if "theme" in req.params: + theme = req.params["theme"].toTheme + let ogType = if video.len > 0: "video" elif rss.len > 0: "object" @@ -118,15 +125,12 @@ proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video=""; proc renderMain*(body: VNode; req: Request; cfg: Config; prefs=defaultPrefs; titleText=""; desc=""; ogTitle=""; rss=""; video=""; images: seq[string] = @[]; banner=""): string = - var theme = toLowerAscii(prefs.theme).replace(" ", "_") - if "theme" in req.params: - theme = toLowerAscii(req.params["theme"]).replace(" ", "_") let canonical = getTwitterLink(req.path, req.params) let node = buildHtml(html(lang="en")): - renderHead(prefs, cfg, titleText, desc, video, images, banner, ogTitle, - theme, rss, canonical) + renderHead(prefs, cfg, req, titleText, desc, video, images, banner, ogTitle, + rss, canonical) body: renderNavbar(cfg, req, rss, canonical) diff --git a/src/views/tweet.nim b/src/views/tweet.nim index f8a570a..f96d978 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -1,6 +1,7 @@ # SPDX-License-Identifier: AGPL-3.0-only import strutils, sequtils, strformat, options import karax/[karaxdsl, vdom, vstyles] +from jester import Request import renderutils import ".."/[types, utils, formatters] @@ -276,7 +277,7 @@ proc renderLocation*(tweet: Tweet): string = text place return $node -proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; prefs: Prefs; path: string): VNode = +proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; req: Request; prefs: Prefs; path: string): VNode = let fullTweet = tweet var retweet: string var tweet = fullTweet @@ -298,7 +299,7 @@ proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; prefs: Prefs; path: string) renderQuote(tweet.quote.get(), prefs, path) buildHtml(tdiv(class="timeline-item")): - renderHead(prefs, cfg) + renderHead(prefs, cfg, req) tdiv(class="tweet-body"): var views = "" renderHeader(tweet, retweet, prefs)