mirror of
https://github.com/zedeus/nitter
synced 2024-11-29 04:50:31 +01:00
Add theme option
This commit is contained in:
parent
9aa4ddb30b
commit
5630a4da32
@ -51,6 +51,9 @@ const prefList*: OrderedTable[string, seq[Pref]] = {
|
||||
],
|
||||
|
||||
"Display": @[
|
||||
Pref(kind: select, name: "theme", label: "Theme",
|
||||
defaultOption: "Dark"),
|
||||
|
||||
Pref(kind: checkbox, name: "hideTweetStats",
|
||||
label: "Hide tweet stats (replies, retweets, likes)",
|
||||
defaultState: false),
|
||||
@ -94,10 +97,12 @@ macro genUpdatePrefs*(): untyped =
|
||||
of input:
|
||||
result.add quote do: prefs.`ident` = xmltree.escape(strip(`value`))
|
||||
of select:
|
||||
let name = pref.name
|
||||
let options = pref.options
|
||||
let default = pref.defaultOption
|
||||
result.add quote do:
|
||||
if `value` in `options`: prefs.`ident` = `value`
|
||||
if `name` == "theme": prefs.`ident` = `value`
|
||||
elif `value` in `options`: prefs.`ident` = `value`
|
||||
else: prefs.`ident` = `default`
|
||||
|
||||
result.add quote do:
|
||||
|
@ -1,4 +1,4 @@
|
||||
import strutils, uri
|
||||
import strutils, uri, os
|
||||
|
||||
import jester
|
||||
|
||||
@ -8,13 +8,17 @@ import ../views/[general, preferences]
|
||||
|
||||
export preferences
|
||||
|
||||
proc findThemes*(dir: string): seq[string] =
|
||||
for kind, path in walkDir(dir / "css" / "themes"):
|
||||
result.add path.splitFile.name.capitalizeAscii
|
||||
|
||||
proc createPrefRouter*(cfg: Config) =
|
||||
router preferences:
|
||||
template savePrefs(): untyped =
|
||||
setCookie("preferences", $prefs.id, daysForward(360), httpOnly=true, secure=cfg.useHttps)
|
||||
|
||||
get "/settings":
|
||||
let html = renderPreferences(cookiePrefs(), refPath())
|
||||
let html = renderPreferences(cookiePrefs(), refPath(), findThemes(cfg.staticDir))
|
||||
resp renderMain(html, request, cfg, "Preferences")
|
||||
|
||||
get "/settings/@i?":
|
||||
|
@ -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")
|
||||
|
@ -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"):
|
||||
|
Loading…
Reference in New Issue
Block a user