2019-09-20 20:56:27 +00:00
|
|
|
import uri
|
2019-07-10 22:42:31 +00:00
|
|
|
import karax/[karaxdsl, vdom]
|
|
|
|
|
2019-08-15 02:00:40 +00:00
|
|
|
import renderutils
|
2019-09-20 20:56:27 +00:00
|
|
|
import ../utils, ../types, ../prefs
|
|
|
|
|
|
|
|
import jester
|
2019-08-07 20:02:19 +00:00
|
|
|
|
2019-07-10 22:42:31 +00:00
|
|
|
const doctype = "<!DOCTYPE html>\n"
|
|
|
|
|
2019-09-20 20:56:27 +00:00
|
|
|
proc renderNavbar*(title, rss: string; req: Request): VNode =
|
|
|
|
let path = $(parseUri(req.path) ? filterParams(req.params))
|
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"):
|
2019-08-12 20:57:43 +00:00
|
|
|
a(class="site-name", href="/"): text title
|
|
|
|
|
|
|
|
a(href="/"): img(class="site-logo", src="/logo.png")
|
|
|
|
|
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"
|
2019-09-15 09:29:14 +00:00
|
|
|
if rss.len > 0:
|
|
|
|
icon "rss", title="RSS Feed", href=rss
|
2019-08-15 02:00:40 +00:00
|
|
|
icon "info-circled", title="About", href="/about"
|
2019-09-05 20:40:36 +00:00
|
|
|
iconReferer "cog", "/settings", path, title="Preferences"
|
2019-08-12 20:57:43 +00:00
|
|
|
|
2019-09-20 20:56:27 +00:00
|
|
|
proc renderMain*(body: VNode; req: Request; title="Nitter"; titleText=""; desc="";
|
2019-09-15 09:29:14 +00:00
|
|
|
rss=""; `type`="article"; video=""; images: seq[string] = @[]): string =
|
2019-09-20 20:56:27 +00:00
|
|
|
let prefs = getPrefs(req.cookies.getOrDefault("preferences"))
|
2019-07-10 22:42:31 +00:00
|
|
|
let node = buildHtml(html(lang="en")):
|
|
|
|
head:
|
2019-08-15 02:00:40 +00:00
|
|
|
link(rel="stylesheet", `type`="text/css", href="/css/style.css")
|
|
|
|
link(rel="stylesheet", `type`="text/css", href="/css/fontello.css")
|
2019-07-10 22:42:31 +00:00
|
|
|
|
2019-09-15 10:57:44 +00:00
|
|
|
if rss.len > 0:
|
|
|
|
link(rel="alternate", `type`="application/rss+xml", href=rss, title="RSS feed")
|
|
|
|
|
2019-08-19 18:25:00 +00:00
|
|
|
if prefs.hlsPlayback:
|
|
|
|
script(src="/js/hls.light.min.js")
|
|
|
|
script(src="/js/hlsPlayback.js")
|
|
|
|
|
2019-08-07 20:02:19 +00:00
|
|
|
title:
|
|
|
|
if titleText.len > 0:
|
|
|
|
text titleText & " | " & title
|
|
|
|
else:
|
|
|
|
text title
|
|
|
|
|
2019-09-07 16:52:27 +00:00
|
|
|
meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
2019-08-07 20:27:24 +00:00
|
|
|
meta(property="og:type", content=`type`)
|
|
|
|
meta(property="og:title", content=titleText)
|
|
|
|
meta(property="og:description", content=desc)
|
2019-09-15 12:03:47 +00:00
|
|
|
meta(property="og:site_name", content="Nitter")
|
2019-08-07 20:02:19 +00:00
|
|
|
|
|
|
|
for url in images:
|
2019-09-13 10:27:04 +00:00
|
|
|
meta(property="og:image", content=getPicUrl(url))
|
2019-08-07 20:02:19 +00:00
|
|
|
|
|
|
|
if video.len > 0:
|
2019-08-07 20:27:24 +00:00
|
|
|
meta(property="og:video:url", content=video)
|
|
|
|
meta(property="og:video:secure_url", content=video)
|
2019-08-07 20:02:19 +00:00
|
|
|
|
2019-07-10 22:42:31 +00:00
|
|
|
body:
|
2019-09-20 20:56:27 +00:00
|
|
|
renderNavbar(title, rss, req)
|
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"):
|
|
|
|
span: text error
|
|
|
|
|
2019-08-15 21:17:13 +00:00
|
|
|
proc showError*(error, title: string): string =
|
2019-09-20 20:56:27 +00:00
|
|
|
renderMain(renderError(error), Request(), title, "Error")
|