Add theme option

This commit is contained in:
Zed
2019-10-23 11:48:08 +02:00
parent 9aa4ddb30b
commit 5630a4da32
4 changed files with 21 additions and 6 deletions

View File

@@ -30,10 +30,12 @@ proc renderNavbar*(title, rss: string; req: Request): VNode =
proc renderMain*(body: VNode; req: Request; cfg: Config; titleText=""; desc="";
rss=""; `type`="article"; video=""; images: seq[string] = @[]): string =
let prefs = getPrefs(req.cookies.getOrDefault("preferences"), cfg.hostname)
let theme = "/css/themes/" & toLowerAscii(prefs.theme) & ".css"
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")
link(rel="stylesheet", `type`="text/css", href=theme)
link(rel="apple-touch-icon", sizes="180x180", href="/apple-touch-icon.png")
link(rel="icon", type="image/png", sizes="32x32", href="/favicon-32x32.png")

View File

@@ -1,4 +1,4 @@
import tables, macros, strutils
import tables, macros, strutils, os
import karax/[karaxdsl, vdom, vstyles]
import renderutils
@@ -22,12 +22,16 @@ macro renderPrefs*(): untyped =
case pref.kind
of checkbox: discard
of select: stmt[0].add newLit(pref.options)
of input: stmt[0].add newLit(pref.placeholder)
of select:
if pref.name == "theme":
stmt[0].add ident("themes")
else:
stmt[0].add newLit(pref.options)
result[2].add stmt
proc renderPreferences*(prefs: Prefs; path: string): VNode =
proc renderPreferences*(prefs: Prefs; path: string; themes: seq[string]): VNode =
buildHtml(tdiv(class="overlay-panel")):
fieldset(class="preferences"):
form(`method`="post", action="/saveprefs"):