Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/art-deco. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strconv"
|
|
)
|
|
|
|
// parseHeadingLevel reads "level" from a content map, defaulting to 2 and clamping to 1..6.
|
|
func parseHeadingLevel(content map[string]any) int {
|
|
if v, ok := content["level"].(float64); ok {
|
|
return clampInt(int(v), 1, 6)
|
|
}
|
|
if v, ok := content["level"].(int); ok {
|
|
return clampInt(v, 1, 6)
|
|
}
|
|
if v, ok := content["level"].(string); ok {
|
|
if i, err := strconv.Atoi(v); err == nil {
|
|
return clampInt(i, 1, 6)
|
|
}
|
|
}
|
|
return 2
|
|
}
|
|
|
|
// ArtDecoHeadingBlock overrides the built-in "heading" block when the Art Deco theme is active.
|
|
// Content: {"text": "...", "level": 1-6, "textClass": "optional-utility-classes"}
|
|
func ArtDecoHeadingBlock(ctx context.Context, content map[string]any) string {
|
|
data := HeadingData{
|
|
Text: getString(content, "text"),
|
|
Level: parseHeadingLevel(content),
|
|
ExtraCls: getString(content, "textClass"),
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = artDecoHeadingComponent(data).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// HeadingData is the typed view for the heading override component.
|
|
type HeadingData struct {
|
|
Text string
|
|
Level int
|
|
ExtraCls string
|
|
}
|