general.nim 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import karax/[karaxdsl, vdom]
  2. import ../utils
  3. const doctype = "<!DOCTYPE html>\n"
  4. proc renderMain*(body: VNode; title="Nitter"; titleText=""; desc="";
  5. `type`="article"; video=""; images: seq[string] = @[]): string =
  6. let node = buildHtml(html(lang="en")):
  7. head:
  8. link(rel="stylesheet", `type`="text/css", href="/style.css")
  9. title:
  10. if titleText.len > 0:
  11. text titleText & " | " & title
  12. else:
  13. text title
  14. meta(name="og:type", content=`type`)
  15. meta(name="og:title", content=titleText)
  16. meta(name="og:description", content=desc)
  17. meta(name="og:site_name", content="Twitter")
  18. for url in images:
  19. meta(name="og:image", content=getSigUrl(url, "pic"))
  20. if video.len > 0:
  21. meta(name="og:video:url", content=video)
  22. meta(name="og:video:secure_url", content=video)
  23. meta(name="og:video:type", content="text/html")
  24. meta(name="og:video:width", content="1200")
  25. meta(name="og:video:height", content="675")
  26. body:
  27. nav(id="nav", class="nav-bar container"):
  28. tdiv(class="inner-nav"):
  29. tdiv(class="item"):
  30. a(href="/", class="site-name"): text title
  31. tdiv(id="content", class="container"):
  32. body
  33. result = doctype & $node
  34. proc renderSearch*(): VNode =
  35. buildHtml(tdiv(class="panel")):
  36. tdiv(class="search-panel"):
  37. form(`method`="post", action="search"):
  38. input(`type`="text", name="query", placeholder="Enter usernames...")
  39. button(`type`="submit"): text "🔎"
  40. proc renderError*(error: string): VNode =
  41. buildHtml(tdiv(class="panel")):
  42. tdiv(class="error-panel"):
  43. span: text error
  44. proc showError*(error: string; title: string): string =
  45. renderMain(renderError(error), title=title, titleText="Error")