mirror of https://github.com/go-gitea/gitea
Initial support for colorblindness-friendly themes (#30625)
Initial support for #25680 This PR only adds some simple styles from GitHub, it is big enough and it focuses on adding the necessary framework-level supports. More styles could be fine-tuned later.pull/30640/head^2
parent
dd2aaadce3
commit
b79e3db264
@ -0,0 +1,74 @@ |
|||||||
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
package webtheme |
||||||
|
|
||||||
|
import ( |
||||||
|
"sort" |
||||||
|
"strings" |
||||||
|
"sync" |
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/container" |
||||||
|
"code.gitea.io/gitea/modules/log" |
||||||
|
"code.gitea.io/gitea/modules/public" |
||||||
|
"code.gitea.io/gitea/modules/setting" |
||||||
|
) |
||||||
|
|
||||||
|
var ( |
||||||
|
availableThemes []string |
||||||
|
availableThemesSet container.Set[string] |
||||||
|
themeOnce sync.Once |
||||||
|
) |
||||||
|
|
||||||
|
func initThemes() { |
||||||
|
availableThemes = nil |
||||||
|
defer func() { |
||||||
|
availableThemesSet = container.SetOf(availableThemes...) |
||||||
|
if !availableThemesSet.Contains(setting.UI.DefaultTheme) { |
||||||
|
setting.LogStartupProblem(1, log.ERROR, "Default theme %q is not available, please correct the '[ui].DEFAULT_THEME' setting in the config file", setting.UI.DefaultTheme) |
||||||
|
} |
||||||
|
}() |
||||||
|
cssFiles, err := public.AssetFS().ListFiles("/assets/css") |
||||||
|
if err != nil { |
||||||
|
log.Error("Failed to list themes: %v", err) |
||||||
|
availableThemes = []string{setting.UI.DefaultTheme} |
||||||
|
return |
||||||
|
} |
||||||
|
var foundThemes []string |
||||||
|
for _, name := range cssFiles { |
||||||
|
name, ok := strings.CutPrefix(name, "theme-") |
||||||
|
if !ok { |
||||||
|
continue |
||||||
|
} |
||||||
|
name, ok = strings.CutSuffix(name, ".css") |
||||||
|
if !ok { |
||||||
|
continue |
||||||
|
} |
||||||
|
foundThemes = append(foundThemes, name) |
||||||
|
} |
||||||
|
if len(setting.UI.Themes) > 0 { |
||||||
|
allowedThemes := container.SetOf(setting.UI.Themes...) |
||||||
|
for _, theme := range foundThemes { |
||||||
|
if allowedThemes.Contains(theme) { |
||||||
|
availableThemes = append(availableThemes, theme) |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
availableThemes = foundThemes |
||||||
|
} |
||||||
|
sort.Strings(availableThemes) |
||||||
|
if len(availableThemes) == 0 { |
||||||
|
setting.LogStartupProblem(1, log.ERROR, "No theme candidate in asset files, but Gitea requires there should be at least one usable theme") |
||||||
|
availableThemes = []string{setting.UI.DefaultTheme} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func GetAvailableThemes() []string { |
||||||
|
themeOnce.Do(initThemes) |
||||||
|
return availableThemes |
||||||
|
} |
||||||
|
|
||||||
|
func IsThemeAvailable(name string) bool { |
||||||
|
themeOnce.Do(initThemes) |
||||||
|
return availableThemesSet.Contains(name) |
||||||
|
} |
@ -1,2 +1,2 @@ |
|||||||
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{AssetVersion}}"> |
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/index.css?v={{AssetVersion}}"> |
||||||
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{ThemeName .SignedUser | PathEscape}}.css?v={{AssetVersion}}"> |
<link rel="stylesheet" href="{{AssetUrlPrefix}}/css/theme-{{UserThemeName .SignedUser | PathEscape}}.css?v={{AssetVersion}}"> |
||||||
|
@ -0,0 +1,11 @@ |
|||||||
|
@import "./theme-gitea-dark.css"; |
||||||
|
|
||||||
|
/* red/green colorblind-friendly colors */ |
||||||
|
/* from GitHub: --diffBlob-addition-*, --diffBlob-deletion-*, etc */ |
||||||
|
:root { |
||||||
|
--color-diff-added-word-bg: #388bfd66; |
||||||
|
--color-diff-added-row-bg: #388bfd26; |
||||||
|
|
||||||
|
--color-diff-removed-word-bg: #db6d2866; |
||||||
|
--color-diff-removed-row-bg: #db6d2826; |
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
@import "./theme-gitea-light.css"; |
||||||
|
|
||||||
|
/* red/green colorblind-friendly colors */ |
||||||
|
/* from GitHub: --diffBlob-addition-*, --diffBlob-deletion-*, etc */ |
||||||
|
:root { |
||||||
|
--color-diff-added-word-bg: #54aeff66; |
||||||
|
--color-diff-added-row-bg: #ddf4ff80; |
||||||
|
|
||||||
|
--color-diff-removed-word-bg: #ffb77c80; |
||||||
|
--color-diff-removed-row-bg: #fff1e580; |
||||||
|
} |
Loading…
Reference in new issue