Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add theme support using environment variable #145

Merged
merged 6 commits into from
Jul 25, 2024

Conversation

httpjamesm
Copy link
Owner

@httpjamesm httpjamesm commented Jul 25, 2024

Related to #140

Add support for theme environment variable and update theme switching logic.

  • CSS Changes: Modify public/globals.css to handle the data-theme attribute for light and dark themes while keeping the prefers-color-scheme media query.
  • Home Route: Update src/routes/home.go to read the THEME environment variable and pass it to the template.
  • Question Route: Update src/routes/question.go to read the THEME environment variable and pass it to the template.
  • Home Template: Modify templates/home.html to add a data-theme attribute to the html tag and set its value based on the THEME environment variable.
  • Question Template: Modify templates/question.html to add a data-theme attribute to the html tag and set its value based on the THEME environment variable.

For more details, open the Copilot Workspace session.

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).
@httpjamesm
Copy link
Owner Author

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.

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).
@httpjamesm
Copy link
Owner Author

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.

@httpjamesm httpjamesm merged commit 4c971f3 into main Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant