From 7f15993a74c8dacd8177801ee46fde7e7e666e32 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 15:23:53 +0200 Subject: [PATCH 01/13] crude implementation of embedding tweets --- src/nitter.nim | 4 +++- src/routes/embedtweet.nim | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/routes/embedtweet.nim diff --git a/src/nitter.nim b/src/nitter.nim index 9f8fcb7..411c9a3 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -10,7 +10,7 @@ import types, config, prefs, formatters, redis_cache, http_pool, tokens import views/[general, about] import routes/[ preferences, timeline, status, media, search, rss, list, debug, - unsupported, embed, resolver, router_utils] + unsupported, embed, resolver, router_utils, embedtweet] const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances" const issuesUrl = "https://github.com/zedeus/nitter/issues" @@ -51,6 +51,7 @@ createMediaRouter(cfg) createEmbedRouter(cfg) createRssRouter(cfg) createDebugRouter(cfg) +createEmbedTweetRouter(cfg) settings: port = Port(cfg.port) @@ -101,3 +102,4 @@ routes: extend media, "" extend embed, "" extend debug, "" + extend embedtweet, "" diff --git a/src/routes/embedtweet.nim b/src/routes/embedtweet.nim new file mode 100644 index 0000000..d318e67 --- /dev/null +++ b/src/routes/embedtweet.nim @@ -0,0 +1,22 @@ +import asyncdispatch, strutils, uri, options +import jester, karax/vdom + +import router_utils +import ".."/views/[general, tweet] +import ".."/[types, api] + +export vdom +export router_utils +export api, tweet, general + +proc createEmbedTweetRouter*(cfg: Config) = + router embedtweet: + get "/embed/Tweet.html": + let + prefs = cookiePrefs() + t = (await getTweet(@"id")).tweet + + resp ($renderHead(prefs, cfg) & $renderTweet(t, prefs, getPath(), mainTweet=true)) + + + From 0d3469df667818005f60da81beb5310fe229a7bf Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 19:01:47 +0200 Subject: [PATCH 02/13] changed code to be not shit --- src/formatters.nim | 16 ++++++----- src/nitter.nim | 4 +-- src/routes/embed.nim | 17 +++++++++--- src/routes/embedtweet.nim | 22 --------------- src/routes/router_utils.nim | 4 +-- src/views/tweet.nim | 54 +++++++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+), 37 deletions(-) delete mode 100644 src/routes/embedtweet.nim diff --git a/src/formatters.nim b/src/formatters.nim index b251ccf..2ae3077 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -32,23 +32,25 @@ proc getUrlPrefix*(cfg: Config): string = if cfg.useHttps: https & cfg.hostname else: "http://" & cfg.hostname -proc stripHtml*(text: string): string = +proc shortLink*(text: string; length=28): string = + result = text.replace(wwwRegex, "") + if result.len > length: + result = result[0 ..< length] & "…" + +proc stripHtml*(text: string; shorten=false): string = var html = parseHtml(text) for el in html.findAll("a"): let link = el.attr("href") if "http" in link: if el.len == 0: continue - el[0].text = link + el[0].text = + if shorten: link.shortLink + else: link html.innerText() proc sanitizeXml*(text: string): string = text.replace(illegalXmlRegex, "") -proc shortLink*(text: string; length=28): string = - result = text.replace(wwwRegex, "") - if result.len > length: - result = result[0 ..< length] & "…" - proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string = result = body diff --git a/src/nitter.nim b/src/nitter.nim index 411c9a3..9f8fcb7 100644 --- a/src/nitter.nim +++ b/src/nitter.nim @@ -10,7 +10,7 @@ import types, config, prefs, formatters, redis_cache, http_pool, tokens import views/[general, about] import routes/[ preferences, timeline, status, media, search, rss, list, debug, - unsupported, embed, resolver, router_utils, embedtweet] + unsupported, embed, resolver, router_utils] const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances" const issuesUrl = "https://github.com/zedeus/nitter/issues" @@ -51,7 +51,6 @@ createMediaRouter(cfg) createEmbedRouter(cfg) createRssRouter(cfg) createDebugRouter(cfg) -createEmbedTweetRouter(cfg) settings: port = Port(cfg.port) @@ -102,4 +101,3 @@ routes: extend media, "" extend embed, "" extend debug, "" - extend embedtweet, "" diff --git a/src/routes/embed.nim b/src/routes/embed.nim index d9a9ee9..9a4c85b 100644 --- a/src/routes/embed.nim +++ b/src/routes/embed.nim @@ -1,9 +1,12 @@ # SPDX-License-Identifier: AGPL-3.0-only import asyncdispatch, strutils, options -import jester -import ".."/[types, api], ../views/embed +import jester, karax/vdom +import ".."/[types, api], ../views/[embed, tweet, general] +import router_utils -export api, embed +export api, embed, vdom +export tweet, general +export router_utils proc createEmbedRouter*(cfg: Config) = router embed: @@ -13,3 +16,11 @@ proc createEmbedRouter*(cfg: Config) = resp Http404 resp renderVideoEmbed(cfg, convo.tweet) + + get "/@user/status/@id/embedded": + let + tweet = (await getTweet(@"id")).tweet + prefs = cookiePrefs() + path = getPath() + + resp $renderEmbeddedTweet(tweet, cfg, prefs, path) diff --git a/src/routes/embedtweet.nim b/src/routes/embedtweet.nim deleted file mode 100644 index d318e67..0000000 --- a/src/routes/embedtweet.nim +++ /dev/null @@ -1,22 +0,0 @@ -import asyncdispatch, strutils, uri, options -import jester, karax/vdom - -import router_utils -import ".."/views/[general, tweet] -import ".."/[types, api] - -export vdom -export router_utils -export api, tweet, general - -proc createEmbedTweetRouter*(cfg: Config) = - router embedtweet: - get "/embed/Tweet.html": - let - prefs = cookiePrefs() - t = (await getTweet(@"id")).tweet - - resp ($renderHead(prefs, cfg) & $renderTweet(t, prefs, getPath(), mainTweet=true)) - - - diff --git a/src/routes/router_utils.nim b/src/routes/router_utils.nim index 7159890..a071a0d 100644 --- a/src/routes/router_utils.nim +++ b/src/routes/router_utils.nim @@ -4,12 +4,12 @@ from jester import Request, cookies import ../views/general import ".."/[utils, prefs, types] -export utils, prefs, types +export utils, prefs, types, uri template savePref*(pref, value: string; req: Request; expire=false) = if not expire or pref in cookies(req): setCookie(pref, value, daysForward(when expire: -10 else: 360), - httpOnly=true, secure=cfg.useHttps) + httpOnly=true, secure=cfg.useHttps, sameSite=None) template cookiePrefs*(): untyped {.dirty.} = getPrefs(cookies(request)) diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 7494685..3d05993 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -4,6 +4,7 @@ import karax/[karaxdsl, vdom, vstyles] import renderutils import ".."/[types, utils, formatters] +import general proc getSmallPic(url: string): string = result = url @@ -275,6 +276,59 @@ proc renderLocation*(tweet: Tweet): string = text place return $node +proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; prefs: Prefs; path: string): VNode = + let fullTweet = tweet + var retweet: string + var tweet = fullTweet + if tweet.retweet.isSome: + tweet = tweet.retweet.get + retweet = fullTweet.profile.fullname + + # handle unavailable + + buildHtml(tdiv(class="timeline-item")): + renderHead(prefs, cfg) + tdiv(class="tweet-body"): + var views = "" + renderHeader(tweet, retweet, prefs) + + var tweetClass = "tweet-content media-body" + if prefs.bidiSupport: + tweetClass &= " tweet-bidi" + + tdiv(class=tweetClass, dir="auto"): + verbatim replaceUrls(tweet.text, prefs) & renderLocation(tweet) + + if tweet.attribution.isSome: + renderAttribution(tweet.attribution.get(), prefs) + + if tweet.card.isSome: + renderCard(tweet.card.get(), prefs, path) + + if tweet.photos.len > 0: + renderAlbum(tweet) + elif tweet.video.isSome: + renderVideo(tweet.video.get(), prefs, path) + views = tweet.video.get().views + elif tweet.gif.isSome: + renderGif(tweet.gif.get(), prefs) + views = "GIF" + + if tweet.poll.isSome: + renderPoll(tweet.poll.get()) + + if tweet.quote.isSome: + renderQuote(tweet.quote.get(), prefs, path) + + p(class="tweet-published"): text getTime(tweet) + + if tweet.mediaTags.len > 0: + renderMediaTags(tweet.mediaTags) + + if not prefs.hideTweetStats: + renderStats(tweet.stats, views) + + proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0; last=false; showThread=false; mainTweet=false; afterTweet=false): VNode = var divClass = class From 3579bd8e3036d165efdcd794b20f8afc14bc39c4 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 19:17:10 +0200 Subject: [PATCH 03/13] handled unavailable in renderEmbeddedTweet --- src/views/tweet.nim | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 3d05993..f8a570a 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -284,7 +284,18 @@ proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; prefs: Prefs; path: string) tweet = tweet.retweet.get retweet = fullTweet.profile.fullname - # handle unavailable + if not tweet.available: + return buildHtml(tdiv(class="unavailable timeline-item")): + tdiv(class="unavailable-box"): + if tweet.tombstone.len > 0: + text tweet.tombstone + elif tweet.text.len > 0: + text tweet.text + else: + text "This tweet is unavailable" + + if tweet.quote.isSome: + renderQuote(tweet.quote.get(), prefs, path) buildHtml(tdiv(class="timeline-item")): renderHead(prefs, cfg) From 875a2c538796924e7cd8e03aff9b0930aac42178 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 19:34:10 +0200 Subject: [PATCH 04/13] 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) From 817501a5166e39c6ebea1c661210f651d0d361c2 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 19:44:09 +0200 Subject: [PATCH 05/13] wrapped embedded tweet in div and changed css also bumped css version --- src/sass/tweet/_base.scss | 15 +++++++++++++++ src/views/general.nim | 2 +- src/views/tweet.nim | 5 ++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/sass/tweet/_base.scss b/src/sass/tweet/_base.scss index 80a1171..d624fb8 100644 --- a/src/sass/tweet/_base.scss +++ b/src/sass/tweet/_base.scss @@ -98,6 +98,8 @@ } .avatar { + position: absolute; + &.round { border-radius: 50%; } @@ -110,6 +112,19 @@ } } +.tweet-embed { + display: flex; + flex-direction: column; + justify-content: center; + height: 100%; + + .tweet-body { + display: flex; + flex-direction: column; + max-height: calc(100vh - 0.75em * 2); + } +} + .attribution { display: flex; pointer-events: all; diff --git a/src/views/general.nim b/src/views/general.nim index e514ab8..7267852 100644 --- a/src/views/general.nim +++ b/src/views/general.nim @@ -52,7 +52,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc=""; let opensearchUrl = getUrlPrefix(cfg) & "/opensearch" buildHtml(head): - link(rel="stylesheet", type="text/css", href="/css/style.css?v=10") + link(rel="stylesheet", type="text/css", href="/css/style.css?v=11") link(rel="stylesheet", type="text/css", href="/css/fontello.css?v=2") if theme.len > 0: diff --git a/src/views/tweet.nim b/src/views/tweet.nim index f96d978..667ca16 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -298,7 +298,7 @@ proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; req: Request; prefs: Prefs; if tweet.quote.isSome: renderQuote(tweet.quote.get(), prefs, path) - buildHtml(tdiv(class="timeline-item")): + let body = buildHtml(tdiv(class="timeline-item")): renderHead(prefs, cfg, req) tdiv(class="tweet-body"): var views = "" @@ -339,6 +339,9 @@ proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; req: Request; prefs: Prefs; if not prefs.hideTweetStats: renderStats(tweet.stats, views) + + return buildHtml(tdiv(class="tweet-embed")): + body proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0; From 784d0d42acffebc047b88e483231419b54af20c1 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 19:49:36 +0200 Subject: [PATCH 06/13] minor css change and version bump --- src/sass/tweet/_base.scss | 2 ++ src/views/general.nim | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sass/tweet/_base.scss b/src/sass/tweet/_base.scss index d624fb8..e9965da 100644 --- a/src/sass/tweet/_base.scss +++ b/src/sass/tweet/_base.scss @@ -117,6 +117,8 @@ flex-direction: column; justify-content: center; height: 100%; + + .tweet-content { font-size: 18px } .tweet-body { display: flex; diff --git a/src/views/general.nim b/src/views/general.nim index 7267852..f909eb0 100644 --- a/src/views/general.nim +++ b/src/views/general.nim @@ -52,7 +52,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc=""; let opensearchUrl = getUrlPrefix(cfg) & "/opensearch" buildHtml(head): - link(rel="stylesheet", type="text/css", href="/css/style.css?v=11") + link(rel="stylesheet", type="text/css", href="/css/style.css?v=12") link(rel="stylesheet", type="text/css", href="/css/fontello.css?v=2") if theme.len > 0: From 90eae2669b66090a401309cdf030112b0a407788 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 20:11:51 +0200 Subject: [PATCH 07/13] fixed stupid code (sorry) --- src/views/tweet.nim | 72 ++++----------------------------------------- 1 file changed, 5 insertions(+), 67 deletions(-) diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 667ca16..e211128 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -277,73 +277,6 @@ proc renderLocation*(tweet: Tweet): string = text place return $node -proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; req: Request; prefs: Prefs; path: string): VNode = - let fullTweet = tweet - var retweet: string - var tweet = fullTweet - if tweet.retweet.isSome: - tweet = tweet.retweet.get - retweet = fullTweet.profile.fullname - - if not tweet.available: - return buildHtml(tdiv(class="unavailable timeline-item")): - tdiv(class="unavailable-box"): - if tweet.tombstone.len > 0: - text tweet.tombstone - elif tweet.text.len > 0: - text tweet.text - else: - text "This tweet is unavailable" - - if tweet.quote.isSome: - renderQuote(tweet.quote.get(), prefs, path) - - let body = buildHtml(tdiv(class="timeline-item")): - renderHead(prefs, cfg, req) - tdiv(class="tweet-body"): - var views = "" - renderHeader(tweet, retweet, prefs) - - var tweetClass = "tweet-content media-body" - if prefs.bidiSupport: - tweetClass &= " tweet-bidi" - - tdiv(class=tweetClass, dir="auto"): - verbatim replaceUrls(tweet.text, prefs) & renderLocation(tweet) - - if tweet.attribution.isSome: - renderAttribution(tweet.attribution.get(), prefs) - - if tweet.card.isSome: - renderCard(tweet.card.get(), prefs, path) - - if tweet.photos.len > 0: - renderAlbum(tweet) - elif tweet.video.isSome: - renderVideo(tweet.video.get(), prefs, path) - views = tweet.video.get().views - elif tweet.gif.isSome: - renderGif(tweet.gif.get(), prefs) - views = "GIF" - - if tweet.poll.isSome: - renderPoll(tweet.poll.get()) - - if tweet.quote.isSome: - renderQuote(tweet.quote.get(), prefs, path) - - p(class="tweet-published"): text getTime(tweet) - - if tweet.mediaTags.len > 0: - renderMediaTags(tweet.mediaTags) - - if not prefs.hideTweetStats: - renderStats(tweet.stats, views) - - return buildHtml(tdiv(class="tweet-embed")): - body - - proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0; last=false; showThread=false; mainTweet=false; afterTweet=false): VNode = var divClass = class @@ -422,3 +355,8 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0; if showThread: a(class="show-thread", href=("/i/status/" & $tweet.threadId)): text "Show this thread" + +proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; req: Request; prefs: Prefs; path: string): VNode = + return buildHtml(tdiv(class="tweet-embed")): + renderHead(prefs, cfg, req) + renderTweet(tweet, prefs, path) From a6bd05bca684eba2de14807246387c4b0c32db81 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 20:14:06 +0200 Subject: [PATCH 08/13] fixed more stupid code --- src/views/tweet.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/tweet.nim b/src/views/tweet.nim index e211128..b7d18f0 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -357,6 +357,6 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0; text "Show this thread" proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; req: Request; prefs: Prefs; path: string): VNode = - return buildHtml(tdiv(class="tweet-embed")): + buildHtml(tdiv(class="tweet-embed")): renderHead(prefs, cfg, req) - renderTweet(tweet, prefs, path) + renderTweet(tweet, prefs, path, mainTweet=true) From ac0edc0a41f13e9cce725901eff2ad65f98d5193 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 20:24:06 +0200 Subject: [PATCH 09/13] made twitter embed links redirect to nitter ones --- src/routes/embed.nim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/routes/embed.nim b/src/routes/embed.nim index 2db9a41..b758b52 100644 --- a/src/routes/embed.nim +++ b/src/routes/embed.nim @@ -27,3 +27,11 @@ proc createEmbedRouter*(cfg: Config) = resp Http404 resp $renderEmbeddedTweet(convo.tweet, cfg, request, prefs, path) + + get "/embed/Tweet.html": + let id = @"id" + + if id.len > 0: + redirect("/i/status/" & id & "/embed") + else: + resp Http404 From 74fcc071a3ff811cf10c0b31a74be27397d8a2f0 Mon Sep 17 00:00:00 2001 From: alqeeu Date: Fri, 14 Jan 2022 20:32:50 +0200 Subject: [PATCH 10/13] Update src/sass/tweet/_base.scss Co-authored-by: Zed --- src/sass/tweet/_base.scss | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sass/tweet/_base.scss b/src/sass/tweet/_base.scss index e9965da..aa87ff1 100644 --- a/src/sass/tweet/_base.scss +++ b/src/sass/tweet/_base.scss @@ -118,7 +118,9 @@ justify-content: center; height: 100%; - .tweet-content { font-size: 18px } + .tweet-content { + font-size: 18px + } .tweet-body { display: flex; From 1e027f5edf21f77ccebe3eaf2ea47f616889b7e3 Mon Sep 17 00:00:00 2001 From: alqeeu Date: Fri, 14 Jan 2022 20:33:01 +0200 Subject: [PATCH 11/13] Update src/routes/embed.nim Co-authored-by: Zed --- src/routes/embed.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes/embed.nim b/src/routes/embed.nim index b758b52..31e1bc3 100644 --- a/src/routes/embed.nim +++ b/src/routes/embed.nim @@ -1,7 +1,8 @@ # SPDX-License-Identifier: AGPL-3.0-only import asyncdispatch, strutils, options import jester, karax/vdom -import ".."/[types, api], ../views/[embed, tweet, general] +import ".."/[types, api] +import ../views/[embed, tweet, general] import router_utils export api, embed, vdom From d29186bf8f08b47a0d29f83da16185626b4c8cab Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 20:35:01 +0200 Subject: [PATCH 12/13] stylistic changes --- src/routes/embed.nim | 6 ++---- src/views/tweet.nim | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/routes/embed.nim b/src/routes/embed.nim index b758b52..ec914f0 100644 --- a/src/routes/embed.nim +++ b/src/routes/embed.nim @@ -4,9 +4,7 @@ import jester, karax/vdom import ".."/[types, api], ../views/[embed, tweet, general] import router_utils -export api, embed, vdom -export tweet, general -export router_utils +export api, embed, vdom, tweet, general, router_utils proc createEmbedRouter*(cfg: Config) = router embed: @@ -26,7 +24,7 @@ proc createEmbedRouter*(cfg: Config) = if convo == nil or convo.tweet == nil: resp Http404 - resp $renderEmbeddedTweet(convo.tweet, cfg, request, prefs, path) + resp $renderTweetEmbed(convo.tweet, prefs, path, cfg, request) get "/embed/Tweet.html": let id = @"id" diff --git a/src/views/tweet.nim b/src/views/tweet.nim index b7d18f0..88edac4 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -356,7 +356,7 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0; a(class="show-thread", href=("/i/status/" & $tweet.threadId)): text "Show this thread" -proc renderEmbeddedTweet*(tweet: Tweet; cfg: Config; req: Request; prefs: Prefs; path: string): VNode = +proc renderTweetEmbed*(tweet: Tweet; prefs: Prefs; path: string; cfg: Config; req: Request): VNode = buildHtml(tdiv(class="tweet-embed")): renderHead(prefs, cfg, req) renderTweet(tweet, prefs, path, mainTweet=true) From eff098003f3d3bebdb64ee7feef3cec026c3d4c5 Mon Sep 17 00:00:00 2001 From: Mitarashi Date: Fri, 14 Jan 2022 20:45:02 +0200 Subject: [PATCH 13/13] unified function call styles --- src/routes/embed.nim | 4 ++-- src/views/embed.nim | 2 +- src/views/tweet.nim | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/routes/embed.nim b/src/routes/embed.nim index 7057f67..1a93d40 100644 --- a/src/routes/embed.nim +++ b/src/routes/embed.nim @@ -14,7 +14,7 @@ proc createEmbedRouter*(cfg: Config) = if convo == nil or convo.tweet == nil or convo.tweet.video.isNone: resp Http404 - resp renderVideoEmbed(cfg, request, convo.tweet) + resp renderVideoEmbed(convo.tweet, cfg, request) get "/@user/status/@id/embed": let @@ -25,7 +25,7 @@ proc createEmbedRouter*(cfg: Config) = if convo == nil or convo.tweet == nil: resp Http404 - resp $renderTweetEmbed(convo.tweet, prefs, path, cfg, request) + resp $renderTweetEmbed(convo.tweet, path, prefs, cfg, request) get "/embed/Tweet.html": let id = @"id" diff --git a/src/views/embed.nim b/src/views/embed.nim index edce944..e6afffd 100644 --- a/src/views/embed.nim +++ b/src/views/embed.nim @@ -8,7 +8,7 @@ import general, tweet const doctype = "\n" -proc renderVideoEmbed*(cfg: Config; req: Request; tweet: Tweet): string = +proc renderVideoEmbed*(tweet: Tweet; cfg: Config; req: Request): string = let thumb = get(tweet.video).thumb let vidUrl = getVideoEmbed(cfg, tweet.id) let prefs = Prefs(hlsPlayback: true) diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 88edac4..e8dfc83 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -356,7 +356,7 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class=""; index=0; a(class="show-thread", href=("/i/status/" & $tweet.threadId)): text "Show this thread" -proc renderTweetEmbed*(tweet: Tweet; prefs: Prefs; path: string; cfg: Config; req: Request): VNode = +proc renderTweetEmbed*(tweet: Tweet; path: string; prefs: Prefs; cfg: Config; req: Request): VNode = buildHtml(tdiv(class="tweet-embed")): renderHead(prefs, cfg, req) renderTweet(tweet, prefs, path, mainTweet=true)