feat!: APP_URL env, theme switcher icon with redirect
This commit is contained in:
parent
3d53fd5806
commit
d92edafb03
@ -24,6 +24,25 @@ body {
|
|||||||
width: fit-content;
|
width: fit-content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
width: 2rem;
|
||||||
|
min-width: 2rem;
|
||||||
|
height: 2rem;
|
||||||
|
min-height: 2rem;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon img {
|
||||||
|
background: white;
|
||||||
|
border-radius: 50%;
|
||||||
|
padding: .25rem;
|
||||||
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
background-color: var(--code-bg);
|
background-color: var(--code-bg);
|
||||||
padding: .15rem;
|
padding: .15rem;
|
||||||
|
@ -2,6 +2,8 @@ package routes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -17,6 +19,23 @@ func ChangeOptions(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
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)
|
||||||
c.String(200, "Images are now %s", text)
|
c.String(200, "Images are now %s", text)
|
||||||
|
case "theme":
|
||||||
|
text := "dark"
|
||||||
|
if c.MustGet("theme").(string) == "dark" {
|
||||||
|
text = "light"
|
||||||
|
}
|
||||||
|
c.SetCookie("theme", text, 60*60*24*365*10, "/", "", false, true)
|
||||||
|
// get redirect url from query
|
||||||
|
redirectUrl := c.Query("redirect_url")
|
||||||
|
if redirectUrl == "" {
|
||||||
|
redirectUrl = "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasPrefix(redirectUrl, os.Getenv("APP_URL")) {
|
||||||
|
redirectUrl = "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Redirect(302, redirectUrl)
|
||||||
default:
|
default:
|
||||||
c.String(400, "400 Bad Request")
|
c.String(400, "400 Bad Request")
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package routes
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/goquery"
|
"github.com/PuerkitoBio/goquery"
|
||||||
@ -157,6 +158,7 @@ func ViewQuestion(c *gin.Context) {
|
|||||||
"imagePolicy": imagePolicy,
|
"imagePolicy": imagePolicy,
|
||||||
"shortenedBody": questionBodyParent.Text()[0:50],
|
"shortenedBody": questionBodyParent.Text()[0:50],
|
||||||
"theme": c.MustGet("theme").(string),
|
"theme": c.MustGet("theme").(string),
|
||||||
|
"currentUrl": fmt.Sprintf("%s/questions/%s/%s", os.Getenv("APP_URL"), questionId, questionTitle),
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,21 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="parent">
|
<div class="parent">
|
||||||
<a href="/" class="logo-link">
|
<div class="header">
|
||||||
<img
|
<a href="/" class="logo-link">
|
||||||
class="logo"
|
<img
|
||||||
src="/static/codecircles.png"
|
class="logo"
|
||||||
alt="4 circles with alternating colors between green and white"
|
src="/static/codecircles.png"
|
||||||
/>
|
alt="4 circles with alternating colors between green and white"
|
||||||
</a>
|
/>
|
||||||
|
</a>
|
||||||
|
<div class="icon">
|
||||||
|
<a href="/options/theme?redirect_url={{ .currentUrl }}">
|
||||||
|
<img src="/static/icons/{{ if eq .theme "dark" }}sun{{
|
||||||
|
else }}moon{{ end }}.svg" alt="Toggle theme" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h1>{{ .title }}</h1>
|
<h1>{{ .title }}</h1>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user