Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/y2k. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package main
|
|
|
|
// getString safely extracts a string value from a content map.
|
|
func getString(content map[string]any, key string) string {
|
|
if v, ok := content[key].(string); ok {
|
|
return v
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// getStringOr returns the string value for key or the default when missing/empty.
|
|
func getStringOr(content map[string]any, key, dflt string) string {
|
|
if v := getString(content, key); v != "" {
|
|
return v
|
|
}
|
|
return dflt
|
|
}
|
|
|
|
// getBool extracts a boolean value, defaulting to dflt when absent.
|
|
func getBool(content map[string]any, key string, dflt bool) bool {
|
|
if v, ok := content[key].(bool); ok {
|
|
return v
|
|
}
|
|
return dflt
|
|
}
|
|
|
|
// getStringSlice extracts a []string from a JSON array of strings.
|
|
func getStringSlice(content map[string]any, key string) []string {
|
|
raw, ok := content[key].([]any)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
out := make([]string, 0, len(raw))
|
|
for _, item := range raw {
|
|
if s, ok := item.(string); ok {
|
|
out = append(out, s)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// getSlice extracts a []map[string]any from a JSON array of objects.
|
|
func getSlice(content map[string]any, key string) []map[string]any {
|
|
raw, ok := content[key].([]any)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
out := make([]map[string]any, 0, len(raw))
|
|
for _, item := range raw {
|
|
if m, ok := item.(map[string]any); ok {
|
|
out = append(out, m)
|
|
}
|
|
}
|
|
return out
|
|
}
|