Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/magazine-bold. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strconv"
|
|
)
|
|
|
|
// HeadingOverrideBlock renders headings with the Magazine Bold display-serif scale
|
|
// and an optional drop-cap on h1.
|
|
//
|
|
// Built-in heading content shape: {"text": "...", "level": 1-6, "textClass": "..."}
|
|
func HeadingOverrideBlock(ctx context.Context, content map[string]any) string {
|
|
text := getString(content, "text")
|
|
textClass := getString(content, "textClass")
|
|
level := parseHeadingLevel(content)
|
|
|
|
var buf bytes.Buffer
|
|
_ = mbHeadingComponent(level, text, textClass).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
|
|
}
|
|
|
|
// mbHeadingBaseClass returns the Magazine Bold class for each heading level.
|
|
// h1 picks up the .text-folio clamp + drop-cap behaviour.
|
|
func mbHeadingBaseClass(level int) string {
|
|
switch level {
|
|
case 1:
|
|
return "font-display text-folio text-foreground mb-dropcap"
|
|
case 2:
|
|
return "font-display text-deck text-foreground"
|
|
case 3:
|
|
return "font-display text-3xl text-foreground"
|
|
case 4:
|
|
return "font-serif-sub text-2xl text-foreground"
|
|
case 5:
|
|
return "font-serif-sub text-xl text-foreground"
|
|
case 6:
|
|
return "font-mono text-kicker text-muted-foreground"
|
|
default:
|
|
return "font-display text-deck text-foreground"
|
|
}
|
|
}
|