From 9542895e03e487cfd0a7c673257cc383295b5d76 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 27 Mar 2025 17:02:05 +0100 Subject: [PATCH] Improve theme picker Signed-off-by: Minecon724 --- modules/theme/theme.go | 12 ++++++++++++ routers/web/user/setting/profile.go | 4 ++++ templates/user/settings/appearance.tmpl | 5 ++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/theme/theme.go b/modules/theme/theme.go index 762926d78f..a1daf31369 100644 --- a/modules/theme/theme.go +++ b/modules/theme/theme.go @@ -78,3 +78,15 @@ func loadThemesInner(assetFs *assetfs.LayeredFS) ([]string, error) { return nil, fmt.Errorf("no themes found") } } + +// GetFriendlyThemeName converts an raw theme name (forgejo-dark) to a friendly name (Forgejo Dark) +// +// Example: forgejo-dark -> Forgejo Dark, catppuccin-maroon-auto -> Catppuccin Maroon Auto +func GetFriendlyThemeName(themeName string) string { + themeName = strings.ReplaceAll(themeName, "-", " ") + + themeName = strings.ToLower(themeName) + themeName = strings.Title(themeName) + + return themeName +} diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 1dee0d641f..7009fb767d 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -345,6 +345,10 @@ func Appearance(ctx *context.Context) { if ctx.Locale.HasKey(fullThemeName) { return ctx.Locale.TrString(fullThemeName) } + + // We should probably cache, because this does some operations on the string + themeName = theme.GetFriendlyThemeName(themeName) + return themeName } diff --git a/templates/user/settings/appearance.tmpl b/templates/user/settings/appearance.tmpl index 12153f78d4..be2b8d9962 100644 --- a/templates/user/settings/appearance.tmpl +++ b/templates/user/settings/appearance.tmpl @@ -15,8 +15,7 @@
{{.CsrfTokenHtml}}
- -