Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/editorial. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strconv"
|
|
)
|
|
|
|
// EditorialHeadingBlock overrides the built-in `heading` block for the
|
|
// editorial template. The override only applies when the active page template
|
|
// is `editorial`; on other templates the built-in heading runs untouched.
|
|
//
|
|
// Content shape mirrors the built-in heading: { "text", "level", "kicker",
|
|
// "textClass" }. The optional "kicker" is editorial-specific (a small-caps
|
|
// label above the H1).
|
|
func EditorialHeadingBlock(ctx context.Context, content map[string]any) string {
|
|
text := getString(content, "text")
|
|
textClass := getString(content, "textClass")
|
|
kicker := getString(content, "kicker")
|
|
level := parseHeadingLevel(content)
|
|
|
|
var buf bytes.Buffer
|
|
_ = editorialHeadingComponent(level, text, textClass, kicker).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// parseHeadingLevel parses content.level into 1-6, defaulting to 2. Accepts
|
|
// number, integer-from-JSON (float64), and string forms.
|
|
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
|
|
}
|