2019-10-07 18:09:56 +02:00
|
|
|
import uri, strutils
|
2019-07-11 00:42:31 +02:00
|
|
|
import karax/[karaxdsl, vdom]
|
|
|
|
|
2019-08-15 04:00:40 +02:00
|
|
|
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
|
|
|
|
2019-07-11 00:42:31 +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 13:07:53 +02:00
|
|
|
let path = $(parseUri(req.path) ? filterParams(req.params))
|
2019-10-08 15:07:10 +02:00
|
|
|
let twitterPath = getTwitterLink(req.path, req.params)
|
2019-10-07 18:09:56 +02:00
|
|
|
|
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"):
|
2019-09-19 04:51:17 +02:00
|
|
|
icon "search", title="Search", href="/search"
|
2019-09-15 11:29:14 +02:00
|
|
|
if rss.len > 0:
|
2019-09-23 01:03:12 +02:00
|
|
|
icon "rss-feed", title="RSS Feed", href=rss
|
2019-10-08 15:07:10 +02:00
|
|
|
icon "bird", title="Open in Twitter", href=twitterPath
|
2019-08-15 04:00:40 +02:00
|
|
|
icon "info-circled", title="About", href="/about"
|
2019-09-05 22:40:36 +02:00
|
|
|
iconReferer "cog", "/settings", path, title="Preferences"
|
2019-08-12 22:57:43 +02:00
|
|
|
|
2019-10-21 05:19:00 +02:00
|
|
|
proc renderMain*(body: VNode; req: Request; cfg: Config; titleText=""; desc="";
|
2019-09-15 11:29:14 +02:00
|
|
|
rss=""; `type`="article"; video=""; images: seq[string] = @[]): string =
|
2019-10-23 14:06:47 +02:00
|
|
|
let prefs = getPrefs(req.cookies.getOrDefault("preferences"), cfg)
|
2019-10-23 11:48:08 +02:00
|
|
|
let theme = "/css/themes/" & toLowerAscii(prefs.theme) & ".css"
|
2019-07-11 00:42:31 +02:00
|
|
|
let node = buildHtml(html(lang="en")):
|
|
|
|
head:
|
2019-08-15 04:00:40 +02:00
|
|
|
link(rel="stylesheet", `type`="text/css", href="/css/style.css")
|
|
|
|
link(rel="stylesheet", `type`="text/css", href="/css/fontello.css")
|
2019-10-23 11:48:08 +02:00
|
|
|
link(rel="stylesheet", `type`="text/css", href=theme)
|
2019-07-11 00:42:31 +02:00
|
|
|
|
2019-09-24 02:43:25 +02: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")
|
|
|
|
|
2019-09-15 12:57:44 +02:00
|
|
|
if rss.len > 0:
|
|
|
|
link(rel="alternate", `type`="application/rss+xml", href=rss, title="RSS feed")
|
|
|
|
|
2019-08-19 20:25:00 +02:00
|
|
|
if prefs.hlsPlayback:
|
|
|
|
script(src="/js/hls.light.min.js")
|
|
|
|
script(src="/js/hlsPlayback.js")
|
|
|
|
|
2019-08-07 22:02:19 +02:00
|
|
|
title:
|
|
|
|
if titleText.len > 0:
|
2019-10-21 05:19:00 +02:00
|
|
|
text titleText & " | " & cfg.title
|
2019-08-07 22:02:19 +02:00
|
|
|
else:
|
2019-10-21 05:19:00 +02:00
|
|
|
text cfg.title
|
2019-08-07 22:02:19 +02:00
|
|
|
|
2019-09-07 18:52:27 +02:00
|
|
|
meta(name="viewport", content="width=device-width, initial-scale=1.0")
|
2019-08-07 22:27:24 +02:00
|
|
|
meta(property="og:type", content=`type`)
|
|
|
|
meta(property="og:title", content=titleText)
|
2019-10-10 17:47:02 +02:00
|
|
|
meta(property="og:description", content=stripHtml(desc))
|
2019-09-15 14:03:47 +02:00
|
|
|
meta(property="og:site_name", content="Nitter")
|
2019-08-07 22:02:19 +02:00
|
|
|
|
|
|
|
for url in images:
|
2019-09-13 12:27:04 +02:00
|
|
|
meta(property="og:image", content=getPicUrl(url))
|
2019-08-07 22:02:19 +02:00
|
|
|
|
|
|
|
if video.len > 0:
|
2019-08-07 22:27:24 +02:00
|
|
|
meta(property="og:video:url", content=video)
|
|
|
|
meta(property="og:video:secure_url", content=video)
|
2019-08-07 22:02:19 +02:00
|
|
|
|
2019-07-11 00:42:31 +02:00
|
|
|
body:
|
2019-10-21 05:19:00 +02:00
|
|
|
renderNavbar(cfg.title, rss, req)
|
2019-07-11 00:42:31 +02:00
|
|
|
|
2019-09-13 19:52:05 +02:00
|
|
|
tdiv(class="container"):
|
2019-07-11 00:42:31 +02:00
|
|
|
body
|
|
|
|
|
|
|
|
result = doctype & $node
|
|
|
|
|
|
|
|
proc renderError*(error: string): VNode =
|
2019-09-13 10:44:21 +02:00
|
|
|
buildHtml(tdiv(class="panel-container")):
|
2019-07-11 00:42:31 +02:00
|
|
|
tdiv(class="error-panel"):
|
|
|
|
span: text error
|
|
|
|
|
2019-10-21 05:19:00 +02:00
|
|
|
template showError*(error: string; cfg: Config): string =
|
|
|
|
renderMain(renderError(error), request, cfg, "Error")
|