general.nim 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import uri, strutils, strformat
  2. import karax/[karaxdsl, vdom]
  3. import renderutils
  4. import ../utils, ../types, ../prefs, ../formatters
  5. import jester
  6. const doctype = "<!DOCTYPE html>\n"
  7. proc renderNavbar*(title, rss: string; req: Request): VNode =
  8. let twitterPath = getTwitterLink(req.path, req.params)
  9. var path = $(parseUri(req.path) ? filterParams(req.params))
  10. if "/status" in path: path.add "#m"
  11. buildHtml(nav):
  12. tdiv(class="inner-nav"):
  13. tdiv(class="nav-item"):
  14. a(class="site-name", href="/"): text title
  15. a(href="/"): img(class="site-logo", src="/logo.png")
  16. tdiv(class="nav-item right"):
  17. icon "search", title="Search", href="/search"
  18. if rss.len > 0:
  19. icon "rss-feed", title="RSS Feed", href=rss
  20. icon "bird", title="Open in Twitter", href=twitterPath
  21. icon "info-circled", title="About", href="/about"
  22. iconReferer "cog", "/settings", path, title="Preferences"
  23. proc renderHead*(prefs: Prefs; cfg: Config; titleText=""; desc=""; video="";
  24. images: seq[string] = @[]): VNode =
  25. let ogType =
  26. if video.len > 0: "video"
  27. elif images.len > 0: "photo"
  28. else: "article"
  29. buildHtml(head):
  30. link(rel="stylesheet", `type`="text/css", href="/css/style.css")
  31. link(rel="stylesheet", `type`="text/css", href="/css/fontello.css")
  32. link(rel="apple-touch-icon", sizes="180x180", href="/apple-touch-icon.png")
  33. link(rel="icon", type="image/png", sizes="32x32", href="/favicon-32x32.png")
  34. link(rel="icon", type="image/png", sizes="16x16", href="/favicon-16x16.png")
  35. link(rel="manifest", href="/site.webmanifest")
  36. link(rel="mask-icon", href="/safari-pinned-tab.svg", color="#ff6c60")
  37. link(rel="search", type="application/opensearchdescription+xml", title=cfg.title,
  38. href="http://localhost:8080/opensearch")
  39. if prefs.hlsPlayback:
  40. script(src="/js/hls.light.min.js")
  41. script(src="/js/hlsPlayback.js")
  42. title:
  43. if titleText.len > 0:
  44. text titleText & " | " & cfg.title
  45. else:
  46. text cfg.title
  47. meta(name="viewport", content="width=device-width, initial-scale=1.0")
  48. meta(property="og:type", content=ogType)
  49. meta(property="og:title", content=titleText)
  50. meta(property="og:description", content=stripHtml(desc))
  51. meta(property="og:site_name", content="Nitter")
  52. for url in images:
  53. meta(property="og:image", content=getPicUrl(url))
  54. if video.len > 0:
  55. meta(property="og:video:url", content=video)
  56. meta(property="og:video:secure_url", content=video)
  57. meta(property="og:video:type", content="text/html")
  58. proc renderMain*(body: VNode; req: Request; cfg: Config; titleText=""; desc="";
  59. rss=""; video=""; images: seq[string] = @[]): string =
  60. let prefs = getPrefs(req.cookies.getOrDefault("preferences"), cfg)
  61. let theme = toLowerAscii(prefs.theme).replace(" ", "_")
  62. let node = buildHtml(html(lang="en")):
  63. renderHead(prefs, cfg, titleText, desc, video, images):
  64. if theme.len > 0:
  65. link(rel="stylesheet", `type`="text/css", href=(&"/css/themes/{theme}.css"))
  66. if rss.len > 0:
  67. link(rel="alternate", `type`="application/rss+xml", href=rss, title="RSS feed")
  68. body:
  69. renderNavbar(cfg.title, rss, req)
  70. tdiv(class="container"):
  71. body
  72. result = doctype & $node
  73. proc renderError*(error: string): VNode =
  74. buildHtml(tdiv(class="panel-container")):
  75. tdiv(class="error-panel"):
  76. span: text error
  77. template showError*(error: string; cfg: Config): string =
  78. renderMain(renderError(error), request, cfg, "Error")