nitter/src/views/general.nim

71 lines
2.1 KiB
Nim
Raw Normal View History

import karax/[karaxdsl, vdom]
import renderutils
2019-08-13 17:44:29 +00:00
import ../utils, ../types
2019-08-07 20:02:19 +00:00
const doctype = "<!DOCTYPE html>\n"
2019-08-12 20:57:43 +00:00
proc renderNavbar*(title: string): VNode =
buildHtml(nav(id="nav", class="nav-bar container")):
tdiv(class="inner-nav"):
tdiv(class="item"):
a(class="site-name", href="/"): text title
a(href="/"): img(class="site-logo", src="/logo.png")
tdiv(class="item right"):
icon "info-circled", title="About", href="/about"
2019-08-19 19:18:18 +00:00
icon "cog", title="Preferences", href="/settings"
2019-08-12 20:57:43 +00:00
2019-08-19 18:25:00 +00:00
proc renderMain*(body: VNode; prefs: Prefs; title="Nitter"; titleText=""; desc="";
2019-08-07 20:02:19 +00:00
`type`="article"; video=""; images: seq[string] = @[]): string =
let node = buildHtml(html(lang="en")):
head:
link(rel="stylesheet", `type`="text/css", href="/css/style.css")
link(rel="stylesheet", `type`="text/css", href="/css/fontello.css")
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-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)
meta(property="og:site_name", content="Twitter")
2019-08-07 20:02:19 +00:00
for url in images:
2019-08-07 20:27:24 +00:00
meta(property="og:image", content=getSigUrl(url, "pic"))
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
body:
2019-08-12 20:57:43 +00:00
renderNavbar(title)
tdiv(id="content", class="container"):
body
result = doctype & $node
proc renderSearch*(): VNode =
buildHtml(tdiv(class="panel")):
tdiv(class="search-panel"):
form(`method`="post", action="/search"):
2019-08-13 18:21:35 +00:00
input(`type`="text", name="query", autofocus="", placeholder="Enter usernames...")
button(`type`="submit"): icon "search"
proc renderError*(error: string): VNode =
buildHtml(tdiv(class="panel")):
tdiv(class="error-panel"):
span: text error
2019-08-15 21:17:13 +00:00
proc showError*(error, title: string): string =
2019-08-19 18:25:00 +00:00
renderMain(renderError(error), Prefs(), title, "Error")