summaryrefslogtreecommitdiff
path: root/internal/generator/themes.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-25 22:13:32 +0300
committerPaul Buetow <paul@buetow.org>2026-04-25 22:13:32 +0300
commita5cb9f7ad4b2bcb7ac367854147f661ab83c5ec1 (patch)
tree96db490ed72dec49c4bc2aba8539fd57f3246f47 /internal/generator/themes.go
parentcc9c69ce748416ad1d9b28592ec463434023d63c (diff)
can swap themes dynamicallyv0.12.0
Diffstat (limited to 'internal/generator/themes.go')
-rw-r--r--internal/generator/themes.go33
1 files changed, 11 insertions, 22 deletions
diff --git a/internal/generator/themes.go b/internal/generator/themes.go
index e7fd3a3..a3a9881 100644
--- a/internal/generator/themes.go
+++ b/internal/generator/themes.go
@@ -6,12 +6,12 @@ import (
"codeberg.org/snonux/snonux/internal/generator/templates"
)
-// fallbackThemeName is returned by getTheme when an unknown name is requested,
-// matching the previous behaviour of the hand-maintained themeRegistry map.
+// fallbackThemeName is used when an unknown name is requested for default
+// metadata, matching the previous behaviour of the per-theme registry.
const fallbackThemeName = "neon"
// themeSet caches the list of theme names available in the embedded template FS
-// so ListThemes and getTheme do not re-read the directory on every call.
+// so ListThemes does not re-read the directory on every call.
var themeSet = loadThemeSet()
func loadThemeSet() map[string]struct{} {
@@ -19,7 +19,7 @@ func loadThemeSet() map[string]struct{} {
if err != nil {
// At build time the embed //go:embed directive guarantees the FS is
// populated, so this should never happen; log and continue with an
- // empty set so getTheme() falls back cleanly.
+ // empty set so callers can fall back cleanly.
log.Printf("warning: could not enumerate themes from embedded FS: %v", err)
return map[string]struct{}{}
}
@@ -31,25 +31,14 @@ func loadThemeSet() map[string]struct{} {
return out
}
-// getTheme returns the HTML template body for the given theme name, loading it
-// from the embedded template FS. It falls back to the neon theme if the name
-// is unknown (preserving previous behaviour of the hand-maintained map).
-func getTheme(name string) string {
- if _, ok := themeSet[name]; !ok {
- name = fallbackThemeName
+// validThemeName returns name if it is a known theme, otherwise the fallback.
+// Callers use this to coerce CLI input ("--theme random" already resolves
+// upstream) so downstream lookups never miss.
+func validThemeName(name string) string {
+ if _, ok := themeSet[name]; ok {
+ return name
}
-
- body, err := templates.Theme(name)
- if err != nil {
- // Last-resort fallback: try neon. If that also fails, return an empty
- // string; template.Parse will then produce a diagnostic error.
- if body, err = templates.Theme(fallbackThemeName); err != nil {
- log.Printf("warning: could not load fallback theme %q: %v", fallbackThemeName, err)
- return ""
- }
- }
-
- return body
+ return fallbackThemeName
}
// ListThemes returns a sorted list of all available theme names.