From 230e2de3de0a3aa416ddfaa2c99cb4a19ae72b5f Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 20 Mar 2025 21:00:48 +0100 Subject: [PATCH] Improve theme picker Signed-off-by: Minecon724 --- modules/theme/theme.go | 20 ++++++++++++++++++++ routers/web/user/setting/profile.go | 1 + templates/user/settings/appearance.tmpl | 9 ++++----- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/modules/theme/theme.go b/modules/theme/theme.go index 762926d78f..370e02592c 100644 --- a/modules/theme/theme.go +++ b/modules/theme/theme.go @@ -16,6 +16,8 @@ const ( key string = "load-themes" ) +var FriendlyThemes map[string]string + var ( group singleflight.Group assetFs *assetfs.LayeredFS @@ -42,6 +44,7 @@ func LoadThemes() error { group.Forget(key) } else { setting.UI.Themes = themes + FriendlyThemes = convertToFriendly(themes) loaded = true } @@ -78,3 +81,20 @@ func loadThemesInner(assetFs *assetfs.LayeredFS) ([]string, error) { return nil, fmt.Errorf("no themes found") } } + +func convertToFriendly(themes []string) map[string]string { + themesFriendly := make(map[string]string) + + for _, theme := range themes { + friendly := theme + + friendly = strings.ReplaceAll(friendly, "-", " ") + + friendly = strings.ToLower(friendly) + friendly = strings.Title(friendly) + + themesFriendly[theme] = friendly + } + + return themesFriendly +} diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 18ad2bf10c..8513caf7c7 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -332,6 +332,7 @@ func Appearance(ctx *context.Context) { } ctx.Data["AllThemes"] = setting.UI.Themes + ctx.Data["FriendlyThemes"] = theme.FriendlyThemes ctx.Data["Title"] = ctx.Tr("settings.appearance") ctx.Data["PageIsSettingsAppearance"] = true diff --git a/templates/user/settings/appearance.tmpl b/templates/user/settings/appearance.tmpl index 3315b7f32e..fb56edf34f 100644 --- a/templates/user/settings/appearance.tmpl +++ b/templates/user/settings/appearance.tmpl @@ -15,20 +15,19 @@
{{.CsrfTokenHtml}}
- -