-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e865de1
commit ed2e69d
Showing
17 changed files
with
116 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package webtheme | ||
|
||
import ( | ||
"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...) | ||
}() | ||
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 | ||
} | ||
if len(availableThemes) == 0 { | ||
log.Error("No theme candidate, 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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
<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}}"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
web_src/css/themes/theme-gitea-dark-protanopia-deuteranopia.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
11 changes: 11 additions & 0 deletions
11
web_src/css/themes/theme-gitea-light-protanopia-deuteranopia.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |