Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions public/globals.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
:root {
--code-bg: #36383d;
--code-fg: #ffffff;
}

:root,
[data-theme="dark"] {
--main-bg: #1b1f26;
--text-color: #fff;
--muted-text-color: #b3b3b3;
--code-bg: #36383d;
--code-fg: #ffffff;
--input-bg: #2b303b;
--input-bg-hover: #3b404b;
--meta-bg: #525262;
Expand All @@ -12,12 +16,10 @@
}

@media (prefers-color-scheme: light) {
:root {
:root:not([data-theme="dark"]) {
--main-bg: #dbdbdb;
--text-color: #000;
--muted-text-color: #636363;
--code-bg: #36383d;
--code-fg: #ffffff;
--input-bg: #bcbcbc;
--input-bg-hover: #a8a8a8;
--meta-bg: #aaa8a8;
Expand All @@ -26,6 +28,17 @@
}
}

[data-theme="light"] {
--main-bg: #dbdbdb;
--text-color: #000;
--muted-text-color: #636363;
--input-bg: #bcbcbc;
--input-bg-hover: #a8a8a8;
--meta-bg: #aaa8a8;
--divider-color: #b5b5b5;
--link-color: #335ad0;
}

a {
color: var(--link-color);
}
Expand Down
5 changes: 5 additions & 0 deletions src/routes/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package routes

import (
"anonymousoverflow/config"
"anonymousoverflow/src/utils"
"fmt"
"regexp"
"strings"
Expand All @@ -10,8 +11,10 @@ import (
)

func GetHome(c *gin.Context) {
theme := utils.GetThemeFromEnv()
c.HTML(200, "home.html", gin.H{
"version": config.Version,
"theme": theme,
})
}

Expand Down Expand Up @@ -68,8 +71,10 @@ func PostHome(c *gin.Context) {
translated := translateUrl(body.URL)

if translated == "" {
theme := utils.GetThemeFromEnv()
c.HTML(400, "home.html", gin.H{
"errorMessage": "Invalid stack overflow/exchange URL",
"theme": theme,
})
return
}
Expand Down
3 changes: 3 additions & 0 deletions src/routes/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package routes

import (
"anonymousoverflow/config"
"anonymousoverflow/src/utils"
"fmt"

"github.com/gin-gonic/gin"
Expand All @@ -17,9 +18,11 @@ 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 := utils.GetThemeFromEnv()
c.HTML(200, "home.html", gin.H{
"successMessage": "Images are now " + text,
"version": config.Version,
"theme": theme,
})
default:
c.String(400, "400 Bad Request")
Expand Down
3 changes: 3 additions & 0 deletions src/routes/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@ func ViewQuestion(c *gin.Context) {
imagePolicy = "'self'"
}

theme := utils.GetThemeFromEnv()

c.HTML(200, "question.html", gin.H{
"question": newFilteredQuestion,
"answers": answers,
"imagePolicy": imagePolicy,
"currentUrl": fmt.Sprintf("%s%s", os.Getenv("APP_URL"), c.Request.URL.Path),
"sortValue": params.SoSortValue,
"domain": domain,
"theme": theme,
})

}
Expand Down
11 changes: 11 additions & 0 deletions src/utils/theme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package utils

import "os"

func GetThemeFromEnv() string {
theme := os.Getenv("THEME")
if theme == "" {
theme = "auto"
}
return theme
}
4 changes: 2 additions & 2 deletions templates/home.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html data-theme="{{ .theme }}">

<head>
<title>AnonymousOverflow - Private frontend for StackOverflow</title>
Expand Down Expand Up @@ -58,4 +58,4 @@ <h2>Get programming help without compromising your privacy.</h2>
</div>
</body>

</html>
</html>
4 changes: 2 additions & 2 deletions templates/question.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html data-theme="{{ .theme }}">

<head>
<title>{{ .question.Title }} | AnonymousOverflow</title>
Expand Down Expand Up @@ -92,4 +92,4 @@ <h2>Answers</h2>
{{ end }}
</body>

</html>
</html>