themes-editorial/masthead.go
Alex Dunmow 1d9a4c8ce6 initial: theme plugin editorial
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>
2026-06-06 14:11:28 +08:00

51 lines
1.5 KiB
Go

package main
import (
"bytes"
"context"
"git.dev.alexdunmow.com/block/core/blocks"
)
// MastheadBlockMeta describes the Editorial masthead block: the publication
// wordmark, an optional kicker line, a hairline rule, and a section nav menu.
// Registered as "editorial:masthead" at runtime.
var MastheadBlockMeta = blocks.BlockMeta{
Key: "masthead",
Title: "Masthead",
Description: "Newspaper-style masthead with Playfair wordmark and hairline rule",
Source: "editorial",
Category: blocks.CategoryNavigation,
}
// MastheadData carries the parsed content for the masthead template.
type MastheadData struct {
Title string
Kicker string
MenuName string
Compact bool
}
// MastheadBlock renders the masthead.
//
// Content shape:
//
// {
// "title": "Editorial", // wordmark, falls back to site name when empty
// "kicker": "EST. 2026", // optional small caption above the wordmark
// "menuName": "main", // optional menu key for section nav (not resolved here)
// "compact": "false" // compact variant for article pages
// }
func MastheadBlock(ctx context.Context, content map[string]any) string {
data := MastheadData{
Title: getStringWithDefault(content, "title", "Editorial"),
Kicker: getString(content, "kicker"),
MenuName: getString(content, "menuName"),
Compact: getBool(content, "compact", false),
}
var buf bytes.Buffer
_ = mastheadComponent(data).Render(ctx, &buf)
return buf.String()
}