From 83d8bc02be90950f0661f56f8d4b12d330dbfdcc Mon Sep 17 00:00:00 2001 From: KushBlazingJudah <59340248+KushBlazingJudah@users.noreply.github.com> Date: Tue, 5 Oct 2021 18:49:08 -0300 Subject: apply theme on load using a cookie --- main.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 8deedd4..140682b 100644 --- a/main.go +++ b/main.go @@ -96,10 +96,6 @@ func main() { } for _, f := range themes { - if f.Name() == "default.css" { - continue - } - if e := path.Ext(f.Name()); e == ".css" { Themes = append(Themes, strings.TrimSuffix(f.Name(), e)) } @@ -633,7 +629,11 @@ func main() { adminData.Themes = &Themes - err := t.ExecuteTemplate(w, "layout", adminData) + if cookie, err := r.Cookie("theme"); err == nil { + adminData.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } + + err = t.ExecuteTemplate(w, "layout", adminData) if err != nil { // TODO: actual error handling log.Printf("mod page: %s\n", err) @@ -673,8 +673,11 @@ func main() { adminData.PostBlacklist = GetRegexBlacklistDB(db) adminData.Themes = &Themes + if cookie, err := r.Cookie("theme"); err == nil { + adminData.ThemeCookie = strings.SplitN(cookie.String(), "=", 2)[1] + } - err := t.ExecuteTemplate(w, "layout", adminData) + err = t.ExecuteTemplate(w, "layout", adminData) if err != nil { // TODO: actual error handling log.Printf("mod page: %s\n", err) -- cgit v1.2.3