feat: import theme icons, set color vars, option cookie

This commit is contained in:
httpjamesm
2022-12-28 11:49:14 -05:00
parent 26c7a5f5ee
commit 3d53fd5806
11 changed files with 68 additions and 27 deletions
+13 -4
View File
@@ -5,19 +5,28 @@ import "github.com/gin-gonic/gin"
func OptionsMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Set("disable_images", false)
c.Set("theme", "dark")
// get cookie
cookie, err := c.Cookie("disable_images")
imagesCookie, err := c.Cookie("disable_images")
if err != nil {
c.Next()
return
}
// check if disable_images is equal to "true"
if cookie == "true" {
if imagesCookie == "true" {
c.Set("disable_images", true)
}
themeCookie, err := c.Cookie("theme")
if err != nil {
c.Next()
return
}
if themeCookie == "light" {
c.Set("theme", "light")
}
c.Next()
}
}
+3
View File
@@ -11,6 +11,7 @@ import (
func GetHome(c *gin.Context) {
c.HTML(200, "home.html", gin.H{
"version": config.Version,
"theme": c.MustGet("theme").(string),
})
}
@@ -24,6 +25,7 @@ func PostHome(c *gin.Context) {
if err := c.ShouldBind(&body); err != nil {
c.HTML(400, "home.html", gin.H{
"errorMessage": "Invalid request body",
"theme": c.MustGet("theme").(string),
})
return
}
@@ -34,6 +36,7 @@ func PostHome(c *gin.Context) {
if !strings.HasPrefix(soLink, "https://stackoverflow.com/questions/") {
c.HTML(400, "home.html", gin.H{
"errorMessage": "Invalid stack overflow URL",
"theme": c.MustGet("theme").(string),
})
return
}
+1
View File
@@ -156,6 +156,7 @@ func ViewQuestion(c *gin.Context) {
"answers": answers,
"imagePolicy": imagePolicy,
"shortenedBody": questionBodyParent.Text()[0:50],
"theme": c.MustGet("theme").(string),
})
}