From bd969567a4b83b708f87f872ddc58504e6727702 Mon Sep 17 00:00:00 2001 From: httpjamesm <51917118+httpjamesm@users.noreply.github.com> Date: Thu, 25 Jul 2024 09:57:47 -0700 Subject: [PATCH] Add theme support using environment variable --- public/globals.css | 28 +++++++++++++++++++++++++++- src/routes/home.go | 6 ++++++ src/routes/question.go | 6 ++++++ templates/home.html | 4 ++-- templates/question.html | 4 ++-- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/public/globals.css b/public/globals.css index 8470cd0..0216442 100644 --- a/public/globals.css +++ b/public/globals.css @@ -26,6 +26,32 @@ } } +[data-theme="dark"] { + --main-bg: #1b1f26; + --text-color: #fff; + --muted-text-color: #b3b3b3; + --code-bg: #36383d; + --code-fg: #ffffff; + --input-bg: #2b303b; + --input-bg-hover: #3b404b; + --meta-bg: #525262; + --divider-color: #42464e; + --link-color: #92adff; +} + +[data-theme="light"] { + --main-bg: #dbdbdb; + --text-color: #000; + --muted-text-color: #636363; + --code-bg: #36383d; + --code-fg: #ffffff; + --input-bg: #bcbcbc; + --input-bg-hover: #a8a8a8; + --meta-bg: #aaa8a8; + --divider-color: #b5b5b5; + --link-color: #335ad0; +} + a { color: var(--link-color); } @@ -78,4 +104,4 @@ details { .fw-nowrap { flex-wrap: nowrap; -} \ No newline at end of file +} diff --git a/src/routes/home.go b/src/routes/home.go index a45b4f7..2d12e9d 100644 --- a/src/routes/home.go +++ b/src/routes/home.go @@ -3,6 +3,7 @@ package routes import ( "anonymousoverflow/config" "fmt" + "os" "regexp" "strings" @@ -10,8 +11,13 @@ import ( ) func GetHome(c *gin.Context) { + theme := os.Getenv("THEME") + if theme == "" { + theme = "auto" + } c.HTML(200, "home.html", gin.H{ "version": config.Version, + "theme": theme, }) } diff --git a/src/routes/question.go b/src/routes/question.go index 7d5f7bf..a7e1a3c 100644 --- a/src/routes/question.go +++ b/src/routes/question.go @@ -101,6 +101,11 @@ func ViewQuestion(c *gin.Context) { imagePolicy = "'self'" } + theme := os.Getenv("THEME") + if theme == "" { + theme = "auto" + } + c.HTML(200, "question.html", gin.H{ "question": newFilteredQuestion, "answers": answers, @@ -108,6 +113,7 @@ func ViewQuestion(c *gin.Context) { "currentUrl": fmt.Sprintf("%s%s", os.Getenv("APP_URL"), c.Request.URL.Path), "sortValue": params.SoSortValue, "domain": domain, + "theme": theme, }) } diff --git a/templates/home.html b/templates/home.html index cb47709..48bae31 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,5 +1,5 @@ - + AnonymousOverflow - Private frontend for StackOverflow @@ -58,4 +58,4 @@ - \ No newline at end of file + diff --git a/templates/question.html b/templates/question.html index a0b41f0..6cff3aa 100644 --- a/templates/question.html +++ b/templates/question.html @@ -1,5 +1,5 @@ - + {{ .question.Title }} | AnonymousOverflow @@ -92,4 +92,4 @@ {{ end }} - \ No newline at end of file +