mirror of
https://github.com/httpjamesm/AnonymousOverflow.git
synced 2024-12-06 19:16:43 +01:00
feat: import theme icons, set color vars, option cookie
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -156,6 +156,7 @@ func ViewQuestion(c *gin.Context) {
|
||||
"answers": answers,
|
||||
"imagePolicy": imagePolicy,
|
||||
"shortenedBody": questionBodyParent.Text()[0:50],
|
||||
"theme": c.MustGet("theme").(string),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user