From 31390edfc4d169bfd0f974357cf786d5af36407b Mon Sep 17 00:00:00 2001 From: httpjamesm <51917118+httpjamesm@users.noreply.github.com> Date: Thu, 25 Jul 2024 10:00:09 -0700 Subject: [PATCH] Propagate theme variable to template in options.go Propagate the `theme` variable from the environment to the template in `src/routes/options.go` * Retrieve the `theme` variable from the environment using `os.Getenv("THEME")` * Set the `theme` variable in the `gin.H` map when rendering the `home.html` template --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/httpjamesm/AnonymousOverflow/pull/145?shareId=6397c9b4-9450-425c-bbbe-019425965d2b). --- src/routes/options.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/routes/options.go b/src/routes/options.go index 1bafa59..9d91e64 100644 --- a/src/routes/options.go +++ b/src/routes/options.go @@ -3,6 +3,7 @@ package routes import ( "anonymousoverflow/config" "fmt" + "os" "github.com/gin-gonic/gin" ) @@ -17,9 +18,14 @@ func ChangeOptions(c *gin.Context) { text = "enabled" } c.SetCookie("disable_images", fmt.Sprintf("%t", !c.MustGet("disable_images").(bool)), 60*60*24*365*10, "/", "", false, true) + theme := os.Getenv("THEME") + if theme == "" { + theme = "auto" + } c.HTML(200, "home.html", gin.H{ "successMessage": "Images are now " + text, "version": config.Version, + "theme": theme, }) default: c.String(400, "400 Bad Request")