Alex Dunmow de55bbebd6 initial: theme plugin pastel-dream
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/pastel-dream.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:11:41 +08:00

83 lines
2.0 KiB
Go

package main
// getString extracts a string value from a content map.
// Returns "" when the key is missing or holds a non-string value.
func getString(content map[string]any, key string) string {
if v, ok := content[key].(string); ok {
return v
}
return ""
}
// getStringOr extracts a string with a fallback for empty/missing values.
func getStringOr(content map[string]any, key, fallback string) string {
if v := getString(content, key); v != "" {
return v
}
return fallback
}
// getFloat extracts a float from content.
func getFloat(content map[string]any, key string, defaultVal float64) float64 {
if v, ok := content[key].(float64); ok {
return v
}
if v, ok := content[key].(int); ok {
return float64(v)
}
return defaultVal
}
// getBoolish reads "yes"/"no" select fields or actual booleans into a bool.
func getBoolish(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 v {
case "yes", "true", "1", "on":
return true
case "no", "false", "0", "off":
return false
}
}
return defaultVal
}
// getSlice extracts a slice of maps from a content map (collections/arrays
// of objects).
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
}
// getStringSlice extracts a slice of strings (e.g. social URLs).
func getStringSlice(content map[string]any, key string) []string {
if v, ok := content[key].([]any); ok {
result := make([]string, 0, len(v))
for _, item := range v {
if s, ok := item.(string); ok && s != "" {
result = append(result, s)
}
}
return result
}
return nil
}
// safeLink returns href if non-empty, otherwise "#".
func safeLink(href string) string {
if href == "" {
return "#"
}
return href
}