httpjamesm 4c971f3121
Add theme support using environment variable (#145)
* Add theme support using environment variable

* 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).

* Move all theme environment variable logic to a utils function

Move theme environment variable logic to a utils function and update routes to use it.

* Add `GetThemeFromEnv` function in `src/utils/theme.go` to derive the theme from environment variables and default to "auto" if not set.
* Update `src/routes/home.go` to import and use `GetThemeFromEnv` in the `GetHome` function.
* Update `src/routes/options.go` to import and use `GetThemeFromEnv` in the `ChangeOptions` function.
* Update `src/routes/question.go` to import and use `GetThemeFromEnv` in the `ViewQuestion` function.


---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/httpjamesm/AnonymousOverflow/pull/145?shareId=a0dab6f3-027c-4f6e-85fe-60e7675d0e70).

* fix: imports removed by copilot

* fix: override theme in posthome

* style: reduced repetition in themes with common vars
2024-07-25 10:50:06 -07:00

62 lines
2.3 KiB
HTML

<!DOCTYPE html>
<html data-theme="{{ .theme }}">
<head>
<title>AnonymousOverflow - Private frontend for StackOverflow</title>
<link rel="stylesheet" href="/static/home.css" />
<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src 'self'; script-src 'none'; img-src 'self';" />
<link rel="icon" href="/static/codecircles.webp" />
<meta name="description" content="View StackOverflow threads in privacy and without the clutter." />
{{ template "sharedHead.html" }}
</head>
<body>
<div class="container">
<div class="title">
<img class="logo" src="/static/codecircles.webp" alt="" />
<h1>Anonymous&shy;Overflow</h1>
</div>
<h2>Get programming help without compromising your privacy.</h2>
<p>
AnonymousOverflow allows you to view StackOverflow threads
without the cluttered interface and exposing your IP address,
browsing habits and other browser fingerprint data to
StackOverflow.
</p>
{{ if .successMessage }}
<div class="success">
<p><b>Success</b>: {{ .successMessage }}</p>
</div>
{{ else}} {{ if .errorMessage }}
<div class="error">
<p><b>Error</b>: {{ .errorMessage }}</p>
</div>
{{end}} {{ end }}
<form method="POST" action="/">
<div class="view-form">
<input class="view-input" type="text" name="url"
placeholder="https://stackoverflow.com/questions/123456/example-url" />
<button class="view-button" type="submit">View</button>
</div>
</form>
<div class="options">
<div class="icon">
<a href="/options/images">
<img src="/static/icons/image.svg" alt="Toggle images" />
</a>
</div>
</div>
<p class="footer">
Brought to you by
<a href="https://github.com/WhateverLabs" target="_blank" rel="noopener noreferrer">Whatever Labs</a>
<a href="https://github.com/httpjamesm/AnonymousOverflow" target="_blank"
rel="noopener noreferrer">Source</a>
• Version {{ .version }}
</p>
</div>
</body>
</html>