Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/noir. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
100 lines
2.7 KiB
Go
100 lines
2.7 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strconv"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// NoirHeadingBlock overrides the built-in heading.
|
|
// Renders with the display-serif family, no underline, generous tracking.
|
|
func NoirHeadingBlock(ctx context.Context, content map[string]any) string {
|
|
text := getString(content, "text")
|
|
textClass := getString(content, "textClass")
|
|
level := parseHeadingLevel(content)
|
|
|
|
var buf bytes.Buffer
|
|
_ = noirHeadingComponent(level, text, textClass).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// parseHeadingLevel parses the heading level from content (1-6, default 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
|
|
}
|
|
|
|
// NoirTextBlock overrides the built-in text block.
|
|
// Renders with the humanist sans family and generous leading.
|
|
func NoirTextBlock(ctx context.Context, content map[string]any) string {
|
|
text := getString(content, "text")
|
|
class := getString(content, "class")
|
|
|
|
var buf bytes.Buffer
|
|
_ = noirTextComponent(text, class).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// NoirImageBlock overrides the built-in image block.
|
|
// Always full-bleed inside its container with a mono caption beneath.
|
|
func NoirImageBlock(ctx context.Context, content map[string]any) string {
|
|
src := blocks.ResolveMediaPath(getString(content, "src"))
|
|
alt := getString(content, "alt")
|
|
caption := getString(content, "caption")
|
|
if caption == "" {
|
|
caption = getString(content, "title")
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = noirImageComponent(src, alt, caption).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// NoirButtonBlock overrides the built-in button.
|
|
// Renders as a hairline 1px outline, no fill, hover inverts.
|
|
func NoirButtonBlock(ctx context.Context, content map[string]any) string {
|
|
text := getString(content, "text")
|
|
if text == "" {
|
|
text = getString(content, "label")
|
|
}
|
|
href := getString(content, "url")
|
|
if href == "" {
|
|
href = getString(content, "href")
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = noirButtonComponent(text, href).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// NoirCardBlock overrides the built-in card.
|
|
// Transparent background, hairline border only.
|
|
func NoirCardBlock(ctx context.Context, content map[string]any) string {
|
|
title := getString(content, "title")
|
|
body := getString(content, "body")
|
|
if body == "" {
|
|
body = getString(content, "text")
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = noirCardComponent(title, body).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|