Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/brutalist. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package main
|
|
|
|
import "strings"
|
|
|
|
// getString 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 ""
|
|
}
|
|
|
|
// getSlice extracts a slice of map[string]any from a content map.
|
|
func getSlice(content map[string]any, key string) []map[string]any {
|
|
if v, ok := content[key].([]any); ok {
|
|
result := make([]map[string]any, 0, len(v))
|
|
for _, item := range v {
|
|
if m, ok := item.(map[string]any); ok {
|
|
result = append(result, m)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// getBool extracts a boolean-ish value from a content map.
|
|
// Accepts native bool plus the string forms "true"/"false" emitted by select-style editors.
|
|
func getBool(content map[string]any, key string, defaultVal bool) bool {
|
|
if v, ok := content[key].(bool); ok {
|
|
return v
|
|
}
|
|
if v, ok := content[key].(string); ok {
|
|
switch strings.ToLower(strings.TrimSpace(v)) {
|
|
case "true", "yes", "1":
|
|
return true
|
|
case "false", "no", "0":
|
|
return false
|
|
}
|
|
}
|
|
return defaultVal
|
|
}
|
|
|
|
// resolveURL returns a safe-ish href value, defaulting to "#" when blank.
|
|
func resolveURL(s string) string {
|
|
s = strings.TrimSpace(s)
|
|
if s == "" {
|
|
return "#"
|
|
}
|
|
return s
|
|
}
|