package main // getString extracts a string value from content map. func getString(content map[string]any, key string) string { if v, ok := content[key].(string); ok { return v } return "" } // getStringDefault extracts a string value from content with a fallback. func getStringDefault(content map[string]any, key, def string) string { if v, ok := content[key].(string); ok && v != "" { return v } return def } // getBool extracts a bool value from content. Accepts native bool, "true"/"false" // strings, and the JSON-encoded float forms ("true" via 1, 0). Defaults to def. func getBool(content map[string]any, key string, def bool) bool { switch v := content[key].(type) { case bool: return v case string: switch v { case "true": return true case "false": return false } case float64: return v != 0 } return def } // getInt extracts an int value from content map (handles float64 from JSON). func getInt(content map[string]any, key string, defaultVal int) int { if v, ok := content[key].(float64); ok { return int(v) } if v, ok := content[key].(int); ok { return v } return defaultVal } // getSlice extracts a slice of maps from content. If the underlying value is // not a JSON array of objects (e.g. malformed content provides a bare string), // the function returns nil so renderers can fall back to their empty state. 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 }