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).
This commit is contained in:
httpjamesm 2024-07-25 10:00:09 -07:00
parent bd969567a4
commit 31390edfc4

View file

@ -3,6 +3,7 @@ package routes
import ( import (
"anonymousoverflow/config" "anonymousoverflow/config"
"fmt" "fmt"
"os"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -17,9 +18,14 @@ func ChangeOptions(c *gin.Context) {
text = "enabled" text = "enabled"
} }
c.SetCookie("disable_images", fmt.Sprintf("%t", !c.MustGet("disable_images").(bool)), 60*60*24*365*10, "/", "", false, true) 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{ c.HTML(200, "home.html", gin.H{
"successMessage": "Images are now " + text, "successMessage": "Images are now " + text,
"version": config.Version, "version": config.Version,
"theme": theme,
}) })
default: default:
c.String(400, "400 Bad Request") c.String(400, "400 Bad Request")