Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/kindergarten. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strconv"
|
|
)
|
|
|
|
// KindergartenHeadingBlock renders a heading with the Kindergarten crayon-underline
|
|
// accent and an optional numeral step badge.
|
|
//
|
|
// Content expects: {"text": "...", "level": 1-6, "textClass": "...", "step": 1-9}
|
|
func KindergartenHeadingBlock(ctx context.Context, content map[string]any) string {
|
|
text := getString(content, "text")
|
|
textClass := getString(content, "textClass")
|
|
level := parseHeadingLevel(content)
|
|
step := parseStep(content)
|
|
|
|
var buf bytes.Buffer
|
|
_ = kgHeadingComponent(level, text, textClass, step).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// parseHeadingLevel parses the level from content, defaulting to 2.
|
|
func parseHeadingLevel(content map[string]any) int {
|
|
if level, ok := content["level"].(float64); ok {
|
|
l := int(level)
|
|
if l >= 1 && l <= 6 {
|
|
return l
|
|
}
|
|
}
|
|
if level, ok := content["level"].(int); ok {
|
|
if level >= 1 && level <= 6 {
|
|
return level
|
|
}
|
|
}
|
|
if level, ok := content["level"].(string); ok {
|
|
if l, err := strconv.Atoi(level); err == nil && l >= 1 && l <= 6 {
|
|
return l
|
|
}
|
|
}
|
|
return 2
|
|
}
|
|
|
|
// parseStep parses an optional step badge (1-9). Returns 0 if not provided
|
|
// or out of range; renderer skips the badge when step == 0.
|
|
func parseStep(content map[string]any) int {
|
|
if v, ok := content["step"].(float64); ok {
|
|
s := int(v)
|
|
if s >= 1 && s <= 9 {
|
|
return s
|
|
}
|
|
}
|
|
if v, ok := content["step"].(int); ok {
|
|
if v >= 1 && v <= 9 {
|
|
return v
|
|
}
|
|
}
|
|
if v, ok := content["step"].(string); ok {
|
|
if s, err := strconv.Atoi(v); err == nil && s >= 1 && s <= 9 {
|
|
return s
|
|
}
|
|
}
|
|
return 0
|
|
}
|