nitter/src/views/general.nim

113 lines
3.9 KiB
Nim
Raw Normal View History

2019-10-27 11:24:09 +01:00
import uri, strutils, strformat
import karax/[karaxdsl, vdom]
import renderutils
2019-10-08 15:07:10 +02:00
import ../utils, ../types, ../prefs, ../formatters
2019-09-20 22:56:27 +02:00
import jester
2019-08-07 22:02:19 +02:00
const doctype = "<!DOCTYPE html>\n"
2019-09-20 22:56:27 +02:00
proc renderNavbar*(title, rss: string; req: Request): VNode =
2019-10-08 15:07:10 +02:00
let twitterPath = getTwitterLink(req.path, req.params)
2019-10-26 17:21:35 +02:00
var path = $(parseUri(req.path) ? filterParams(req.params))
if "/status" in path: path.add "#m"
2019-09-13 19:52:05 +02:00
buildHtml(nav):
2019-08-12 22:57:43 +02:00
tdiv(class="inner-nav"):
2019-09-13 19:52:05 +02:00
tdiv(class="nav-item"):
2019-08-12 22:57:43 +02:00
a(class="site-name", href="/"): text title
a(href="/"): img(class="site-logo", src="/logo.png")
2019-09-13 19:52:05 +02:00
tdiv(class="nav-item right"):
icon "search", title="Search", href="/search"
2019-09-15 11:29:14 +02:00
if rss.len > 0:
icon "rss-feed", title="RSS Feed", href=rss
2019-10-08 15:07:10 +02:00
icon "bird", title="Open in Twitter", href=twitterPath
icon "info-circled", title="About", href="/about"
iconReferer "cog", "/settings", path, title="Preferences"
2019-08-12 22:57:43 +02:00
2019-12-08 12:38:55 +01:00
proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video="";
2020-03-29 23:20:00 +02:00
images: seq[string] = @[]; ogTitle=""): VNode =
2019-12-08 12:38:55 +01:00
let ogType =
if video.len > 0: "video"
elif images.len > 0: "photo"
else: "article"
var opensearchUrl = ""
if cfg.useHttps:
opensearchUrl = "https://" & cfg.hostname & "/opensearch"
else:
opensearchUrl = "http://" & cfg.hostname & "/opensearch"
2019-12-06 15:15:56 +01:00
buildHtml(head):
link(rel="stylesheet", `type`="text/css", href="/css/style.css")
link(rel="stylesheet", `type`="text/css", href="/css/fontello.css")
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")
link(rel="search", type="application/opensearchdescription+xml", title=cfg.title,
href=opensearchUrl)
2019-12-06 15:15:56 +01:00
if prefs.hlsPlayback:
script(src="/js/hls.light.min.js")
script(src="/js/hlsPlayback.js")
2020-01-07 03:00:16 +01:00
if prefs.infiniteScroll:
script(src="/js/infiniteScroll.js")
2019-12-06 15:15:56 +01: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")
2019-12-08 12:38:55 +01:00
meta(property="og:type", content=ogType)
2020-03-29 23:20:00 +02:00
meta(property="og:title", content=(if ogTitle.len > 0: ogTitle else: titleText))
2019-12-06 15:15:56 +01:00
meta(property="og:description", content=stripHtml(desc))
meta(property="og:site_name", content="Nitter")
2020-01-10 01:59:52 +01:00
meta(property="og:locale", content="en_US")
2019-12-06 15:15:56 +01:00
for url in images:
meta(property="og:image", content=getPicUrl(url))
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")
proc renderMain*(body: VNode; req: Request; cfg: Config; titleText=""; desc="";
2020-03-29 23:20:00 +02:00
rss=""; video=""; images: seq[string] = @[]; ogTitle=""): string =
let prefs = getPrefs(req.cookies)
var theme = toLowerAscii(prefs.theme).replace(" ", "_")
if "theme" in req.params:
theme = toLowerAscii(req.params["theme"]).replace(" ", "_")
2019-12-06 15:15:56 +01:00
let node = buildHtml(html(lang="en")):
2020-03-29 23:20:00 +02:00
renderHead(prefs, cfg, titleText, desc, video, images, ogTitle):
2019-10-27 11:24:09 +01:00
if theme.len > 0:
link(rel="stylesheet", `type`="text/css", href=(&"/css/themes/{theme}.css"))
2019-09-15 12:57:44 +02:00
if rss.len > 0:
link(rel="alternate", `type`="application/rss+xml", href=rss, title="RSS feed")
body:
renderNavbar(cfg.title, rss, req)
2019-09-13 19:52:05 +02:00
tdiv(class="container"):
body
result = doctype & $node
proc renderError*(error: string): VNode =
2019-09-13 10:44:21 +02:00
buildHtml(tdiv(class="panel-container")):
tdiv(class="error-panel"):
span: text error
template showError*(error: string; cfg: Config): string =
renderMain(renderError(error), request, cfg, "Error")