2021-12-27 01:37:38 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2019-10-27 10:24:09 +00:00
|
|
|
import uri, strutils, strformat
|
2019-07-10 22:42:31 +00:00
|
|
|
import karax/[karaxdsl, vdom]
|
|
|
|
|
2019-08-15 02:00:40 +00:00
|
|
|
import renderutils
|
2019-10-08 13:07:10 +00:00
|
|
|
import ../utils, ../types, ../prefs, ../formatters
|
2019-09-20 20:56:27 +00:00
|
|
|
|
|
|
|
import jester
|
2019-08-07 20:02:19 +00:00
|
|
|
|
2020-07-04 11:20:54 +00:00
|
|
|
const
|
|
|
|
doctype = "<!DOCTYPE html>\n"
|
|
|
|
lp = readFile("public/lp.svg")
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2022-01-14 17:34:10 +00:00
|
|
|
proc toTheme(theme: string): string =
|
|
|
|
theme.toLowerAscii.replace(" ", "_")
|
|
|
|
|
2021-12-30 02:59:11 +00:00
|
|
|
proc renderNavbar(cfg: Config; req: Request; rss, canonical: string): VNode =
|
2022-01-03 01:12:51 +00:00
|
|
|
var path = req.params.getOrDefault("referer")
|
|
|
|
if path.len == 0:
|
|
|
|
path = $(parseUri(req.path) ? filterParams(req.params))
|
|
|
|
if "/status/" in path: path.add "#m"
|
2019-10-07 16:09:56 +00:00
|
|
|
|
2019-09-13 17:52:05 +00:00
|
|
|
buildHtml(nav):
|
2019-08-12 20:57:43 +00:00
|
|
|
tdiv(class="inner-nav"):
|
2019-09-13 17:52:05 +00:00
|
|
|
tdiv(class="nav-item"):
|
2021-10-02 19:15:52 +00:00
|
|
|
a(class="site-name", href="/"): text cfg.title
|
2019-08-12 20:57:43 +00:00
|
|
|
|
2021-12-26 22:26:50 +00:00
|
|
|
a(href="/"): img(class="site-logo", src="/logo.png", alt="Logo")
|
2019-08-12 20:57:43 +00:00
|
|
|
|
2019-09-13 17:52:05 +00:00
|
|
|
tdiv(class="nav-item right"):
|
2019-09-19 02:51:17 +00:00
|
|
|
icon "search", title="Search", href="/search"
|
2021-12-28 05:21:22 +00:00
|
|
|
if cfg.enableRss and rss.len > 0:
|
2019-09-22 23:03:12 +00:00
|
|
|
icon "rss-feed", title="RSS Feed", href=rss
|
2021-12-30 02:59:11 +00:00
|
|
|
icon "bird", title="Open in Twitter", href=canonical
|
2020-07-04 11:20:54 +00:00
|
|
|
a(href="https://liberapay.com/zedeus"): verbatim lp
|
2020-11-08 00:32:17 +00:00
|
|
|
icon "info", title="About", href="/about"
|
2022-01-03 01:12:51 +00:00
|
|
|
icon "cog", title="Preferences", href=("/settings?referer=" & encodeUrl(path))
|
2019-08-12 20:57:43 +00:00
|
|
|
|
2022-01-14 17:34:10 +00:00
|
|
|
proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
|
|
|
|
video=""; images: seq[string] = @[]; banner=""; ogTitle="";
|
2021-12-30 02:59:11 +00:00
|
|
|
rss=""; canonical=""): VNode =
|
2022-01-14 17:34:10 +00:00
|
|
|
var theme = prefs.theme.toTheme
|
|
|
|
if "theme" in req.params:
|
|
|
|
theme = req.params["theme"].toTheme
|
|
|
|
|
2019-12-08 11:38:55 +00:00
|
|
|
let ogType =
|
|
|
|
if video.len > 0: "video"
|
2021-01-07 22:58:29 +00:00
|
|
|
elif rss.len > 0: "object"
|
2019-12-08 11:38:55 +00:00
|
|
|
elif images.len > 0: "photo"
|
|
|
|
else: "article"
|
|
|
|
|
2021-01-08 01:25:43 +00:00
|
|
|
let opensearchUrl = getUrlPrefix(cfg) & "/opensearch"
|
2020-01-03 15:17:38 +00:00
|
|
|
|
2019-12-06 14:15:56 +00:00
|
|
|
buildHtml(head):
|
2022-02-05 17:43:13 +00:00
|
|
|
link(rel="stylesheet", type="text/css", href="/css/style.css?v=18")
|
2021-01-03 00:36:53 +00:00
|
|
|
link(rel="stylesheet", type="text/css", href="/css/fontello.css?v=2")
|
|
|
|
|
|
|
|
if theme.len > 0:
|
|
|
|
link(rel="stylesheet", type="text/css", href=(&"/css/themes/{theme}.css"))
|
|
|
|
|
2019-12-06 14:15:56 +00:00
|
|
|
link(rel="apple-touch-icon", sizes="180x180", href="/apple-touch-icon.png")
|
|
|
|
link(rel="icon", type="image/png", sizes="32x32", href="/favicon-32x32.png")
|
|
|
|
link(rel="icon", type="image/png", sizes="16x16", href="/favicon-16x16.png")
|
|
|
|
link(rel="manifest", href="/site.webmanifest")
|
|
|
|
link(rel="mask-icon", href="/safari-pinned-tab.svg", color="#ff6c60")
|
2020-01-03 14:47:57 +00:00
|
|
|
link(rel="search", type="application/opensearchdescription+xml", title=cfg.title,
|
2020-01-03 15:17:38 +00:00
|
|
|
href=opensearchUrl)
|
2019-12-06 14:15:56 +00:00
|
|
|
|
2021-12-30 02:59:11 +00:00
|
|
|
if canonical.len > 0:
|
|
|
|
link(rel="canonical", href=canonical)
|
|
|
|
|
2021-12-28 05:21:22 +00:00
|
|
|
if cfg.enableRss and rss.len > 0:
|
2021-01-03 00:36:53 +00:00
|
|
|
link(rel="alternate", type="application/rss+xml", href=rss, title="RSS feed")
|
|
|
|
|
2019-12-06 14:15:56 +00:00
|
|
|
if prefs.hlsPlayback:
|
2021-01-03 00:36:53 +00:00
|
|
|
script(src="/js/hls.light.min.js", `defer`="")
|
|
|
|
script(src="/js/hlsPlayback.js", `defer`="")
|
2019-12-06 14:15:56 +00:00
|
|
|
|
2020-01-07 02:00:16 +00:00
|
|
|
if prefs.infiniteScroll:
|
2021-01-03 00:36:53 +00:00
|
|
|
script(src="/js/infiniteScroll.js", `defer`="")
|
2020-01-07 02:00:16 +00:00
|
|
|
|
2019-12-06 14:15:56 +00:00
|
|
|
title:
|
|
|
|
if titleText.len > 0:
|
|
|
|
text titleText & " | " & cfg.title
|
|
|
|
else:
|
|
|
|
text cfg.title
|
|
|
|
|
|
|
|
meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
2021-12-26 22:26:50 +00:00
|
|
|
meta(name="theme-color", content="#1F1F1F")
|
2019-12-08 11:38:55 +00:00
|
|
|
meta(property="og:type", content=ogType)
|
2020-03-29 21:20:00 +00:00
|
|
|
meta(property="og:title", content=(if ogTitle.len > 0: ogTitle else: titleText))
|
2019-12-06 14:15:56 +00:00
|
|
|
meta(property="og:description", content=stripHtml(desc))
|
|
|
|
meta(property="og:site_name", content="Nitter")
|
2020-01-10 00:59:52 +00:00
|
|
|
meta(property="og:locale", content="en_US")
|
2019-12-06 14:15:56 +00:00
|
|
|
|
2022-02-08 06:29:15 +00:00
|
|
|
if banner.len > 0 and not banner.startsWith('#'):
|
2021-01-07 23:50:10 +00:00
|
|
|
let bannerUrl = getPicUrl(banner)
|
2022-01-02 10:21:03 +00:00
|
|
|
link(rel="preload", type="image/png", href=bannerUrl, `as`="image")
|
2021-01-07 23:50:10 +00:00
|
|
|
|
2019-12-06 14:15:56 +00:00
|
|
|
for url in images:
|
2022-01-03 05:31:10 +00:00
|
|
|
let suffix = if "400x400" in url or url.endsWith("placeholder.png"): ""
|
|
|
|
else: "?name=small"
|
2021-01-07 23:50:10 +00:00
|
|
|
let preloadUrl = getPicUrl(url & suffix)
|
|
|
|
link(rel="preload", type="image/png", href=preloadUrl, `as`="image")
|
|
|
|
|
2021-01-08 01:25:43 +00:00
|
|
|
let image = getUrlPrefix(cfg) & getPicUrl(url)
|
2021-01-07 22:58:29 +00:00
|
|
|
meta(property="og:image", content=image)
|
|
|
|
meta(property="twitter:image:src", content=image)
|
|
|
|
|
|
|
|
if rss.len > 0:
|
|
|
|
meta(property="twitter:card", content="summary")
|
|
|
|
else:
|
|
|
|
meta(property="twitter:card", content="summary_large_image")
|
2019-12-06 14:15:56 +00:00
|
|
|
|
|
|
|
if video.len > 0:
|
|
|
|
meta(property="og:video:url", content=video)
|
|
|
|
meta(property="og:video:secure_url", content=video)
|
|
|
|
meta(property="og:video:type", content="text/html")
|
|
|
|
|
2021-01-07 23:50:10 +00:00
|
|
|
# this is last so images are also preloaded
|
|
|
|
# if this is done earlier, Chrome only preloads one image for some reason
|
|
|
|
link(rel="preload", type="font/woff2", `as`="font",
|
|
|
|
href="/fonts/fontello.woff2?21002321", crossorigin="anonymous")
|
|
|
|
|
2020-06-09 14:45:21 +00:00
|
|
|
proc renderMain*(body: VNode; req: Request; cfg: Config; prefs=defaultPrefs;
|
|
|
|
titleText=""; desc=""; ogTitle=""; rss=""; video="";
|
2021-01-07 23:50:10 +00:00
|
|
|
images: seq[string] = @[]; banner=""): string =
|
2019-12-06 14:15:56 +00:00
|
|
|
|
2021-12-30 02:59:11 +00:00
|
|
|
let canonical = getTwitterLink(req.path, req.params)
|
|
|
|
|
2019-07-10 22:42:31 +00:00
|
|
|
let node = buildHtml(html(lang="en")):
|
2022-01-14 17:34:10 +00:00
|
|
|
renderHead(prefs, cfg, req, titleText, desc, video, images, banner, ogTitle,
|
|
|
|
rss, canonical)
|
2019-09-15 10:57:44 +00:00
|
|
|
|
2019-07-10 22:42:31 +00:00
|
|
|
body:
|
2021-12-30 02:59:11 +00:00
|
|
|
renderNavbar(cfg, req, rss, canonical)
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-09-13 17:52:05 +00:00
|
|
|
tdiv(class="container"):
|
2019-07-10 22:42:31 +00:00
|
|
|
body
|
|
|
|
|
|
|
|
result = doctype & $node
|
|
|
|
|
|
|
|
proc renderError*(error: string): VNode =
|
2019-09-13 08:44:21 +00:00
|
|
|
buildHtml(tdiv(class="panel-container")):
|
2019-07-10 22:42:31 +00:00
|
|
|
tdiv(class="error-panel"):
|
2021-01-07 21:31:29 +00:00
|
|
|
span: verbatim error
|