1
0
mirror of https://github.com/zedeus/nitter synced 2024-11-22 09:57:16 +01:00

moved themes to be handled in renderHead and changed path to /embed

This commit is contained in:
Mitarashi 2022-01-14 19:34:10 +02:00
parent 3579bd8e30
commit 875a2c5387
4 changed files with 24 additions and 15 deletions

View File

@ -15,12 +15,15 @@ proc createEmbedRouter*(cfg: Config) =
if convo == nil or convo.tweet == nil or convo.tweet.video.isNone: if convo == nil or convo.tweet == nil or convo.tweet.video.isNone:
resp Http404 resp Http404
resp renderVideoEmbed(cfg, convo.tweet) resp renderVideoEmbed(cfg, request, convo.tweet)
get "/@user/status/@id/embedded": get "/@user/status/@id/embed":
let let
tweet = (await getTweet(@"id")).tweet convo = await getTweet(@"id")
prefs = cookiePrefs() prefs = cookiePrefs()
path = getPath() 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)

View File

@ -1,18 +1,19 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
import options import options
import karax/[karaxdsl, vdom] import karax/[karaxdsl, vdom]
from jester import Request
import ".."/[types, formatters] import ".."/[types, formatters]
import general, tweet import general, tweet
const doctype = "<!DOCTYPE html>\n" const doctype = "<!DOCTYPE html>\n"
proc renderVideoEmbed*(cfg: Config; tweet: Tweet): string = proc renderVideoEmbed*(cfg: Config; req: Request; tweet: Tweet): string =
let thumb = get(tweet.video).thumb let thumb = get(tweet.video).thumb
let vidUrl = getVideoEmbed(cfg, tweet.id) let vidUrl = getVideoEmbed(cfg, tweet.id)
let prefs = Prefs(hlsPlayback: true) let prefs = Prefs(hlsPlayback: true)
let node = buildHtml(html(lang="en")): 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"): tdiv(class="embed-video"):
renderVideo(get(tweet.video), prefs, "") renderVideo(get(tweet.video), prefs, "")

View File

@ -11,6 +11,9 @@ const
doctype = "<!DOCTYPE html>\n" doctype = "<!DOCTYPE html>\n"
lp = readFile("public/lp.svg") lp = readFile("public/lp.svg")
proc toTheme(theme: string): string =
theme.toLowerAscii.replace(" ", "_")
proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode = proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode =
var path = req.params.getOrDefault("referer") var path = req.params.getOrDefault("referer")
if path.len == 0: 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 "info", title="About", href="/about"
icon "cog", title="Preferences", href=("/settings?referer=" & encodeUrl(path)) icon "cog", title="Preferences", href=("/settings?referer=" & encodeUrl(path))
proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video=""; proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
images: seq[string] = @[]; banner=""; ogTitle=""; theme=""; video=""; images: seq[string] = @[]; banner=""; ogTitle="";
rss=""; canonical=""): VNode = rss=""; canonical=""): VNode =
var theme = prefs.theme.toTheme
if "theme" in req.params:
theme = req.params["theme"].toTheme
let ogType = let ogType =
if video.len > 0: "video" if video.len > 0: "video"
elif rss.len > 0: "object" 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; proc renderMain*(body: VNode; req: Request; cfg: Config; prefs=defaultPrefs;
titleText=""; desc=""; ogTitle=""; rss=""; video=""; titleText=""; desc=""; ogTitle=""; rss=""; video="";
images: seq[string] = @[]; banner=""): string = 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 canonical = getTwitterLink(req.path, req.params)
let node = buildHtml(html(lang="en")): let node = buildHtml(html(lang="en")):
renderHead(prefs, cfg, titleText, desc, video, images, banner, ogTitle, renderHead(prefs, cfg, req, titleText, desc, video, images, banner, ogTitle,
theme, rss, canonical) rss, canonical)
body: body:
renderNavbar(cfg, req, rss, canonical) renderNavbar(cfg, req, rss, canonical)

View File

@ -1,6 +1,7 @@
# SPDX-License-Identifier: AGPL-3.0-only # SPDX-License-Identifier: AGPL-3.0-only
import strutils, sequtils, strformat, options import strutils, sequtils, strformat, options
import karax/[karaxdsl, vdom, vstyles] import karax/[karaxdsl, vdom, vstyles]
from jester import Request
import renderutils import renderutils
import ".."/[types, utils, formatters] import ".."/[types, utils, formatters]
@ -276,7 +277,7 @@ proc renderLocation*(tweet: Tweet): string =
text place text place
return $node 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 let fullTweet = tweet
var retweet: string var retweet: string
var tweet = fullTweet var tweet = fullTweet
@ -298,7 +299,7 @@ proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; prefs: Prefs; path: string)
renderQuote(tweet.quote.get(), prefs, path) renderQuote(tweet.quote.get(), prefs, path)
buildHtml(tdiv(class="timeline-item")): buildHtml(tdiv(class="timeline-item")):
renderHead(prefs, cfg) renderHead(prefs, cfg, req)
tdiv(class="tweet-body"): tdiv(class="tweet-body"):
var views = "" var views = ""
renderHeader(tweet, retweet, prefs) renderHeader(tweet, retweet, prefs)