1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-06 17:41:00 +00:00

Improve themes handling

- Store user theme in session
- Logged out users will keep their theme
- Add theme background color to web manifest and meta tag
This commit is contained in:
Frédéric Guillot 2018-07-18 22:30:05 -07:00
parent c1ab27172c
commit a291d8a38b
15 changed files with 76 additions and 31 deletions

View file

@ -18,12 +18,13 @@ type SessionData struct {
FlashMessage string `json:"flash_message"`
FlashErrorMessage string `json:"flash_error_message"`
Language string `json:"language"`
Theme string `json:"Theme"`
PocketRequestToken string `json:"pocket_request_token"`
}
func (s SessionData) String() string {
return fmt.Sprintf(`CSRF="%s", "OAuth2State="%s", FlashMessage="%s", FlashErrorMessage="%s", Lang="%s"`,
s.CSRF, s.OAuth2State, s.FlashMessage, s.FlashErrorMessage, s.Language)
return fmt.Sprintf(`CSRF=%q, "OAuth2State=%q, FlashMsg=%q, FlashErrorMsg=%q, Lang=%q, Theme=%q`,
s.CSRF, s.OAuth2State, s.FlashMessage, s.FlashErrorMessage, s.Language, s.Theme)
}
// Value converts the session data to JSON.

View file

@ -15,6 +15,18 @@ func Themes() map[string]string {
}
}
// ThemeColor returns the color for the address bar or/and the browser color.
// https://developer.mozilla.org/en-US/docs/Web/Manifest#theme_color
// https://developers.google.com/web/tools/lighthouse/audits/address-bar
func ThemeColor(theme string) string {
switch theme {
case "black":
return "#222"
default:
return "#fff"
}
}
// ValidateTheme validates theme value.
func ValidateTheme(theme string) error {
for key := range Themes() {