themes-editorial/dropcap_intro.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

50 lines
1.5 KiB
Go

package main
import (
"bytes"
"context"
"git.dev.alexdunmow.com/block/core/blocks"
)
// DropcapIntroBlockMeta describes the Editorial drop-cap intro block: an
// opening paragraph whose first letter is rendered as an oxblood drop cap.
// Registered as "editorial:dropcap_intro" at runtime.
var DropcapIntroBlockMeta = blocks.BlockMeta{
Key: "dropcap_intro",
Title: "Drop Cap Intro",
Description: "Opening paragraph with an oxblood Playfair drop cap",
Source: "editorial",
Category: blocks.CategoryTheme,
}
// DropcapIntroData carries parsed drop-cap-intro content.
type DropcapIntroData struct {
Lead string // rich-text payload, trusted upstream
}
// DropcapIntroBlock renders the opening paragraph.
//
// The drop cap is rendered via CSS (::first-letter on the first <p>) rather
// than by extracting the first character server-side. This is the simpler
// path and works for ASCII openers. The spec calls out a known risk: an
// opener starting with `"` or `—` will style the punctuation. That fallback
// is acceptable for this build pass and is documented in BUILD_REPORT.md.
//
// Content shape:
//
// { "lead": "<p>The reform was always going to be quiet.</p>" }
func DropcapIntroBlock(ctx context.Context, content map[string]any) string {
data := DropcapIntroData{
Lead: getString(content, "lead"),
}
if data.Lead == "" {
return ""
}
var buf bytes.Buffer
_ = dropcapIntroComponent(data).Render(ctx, &buf)
return buf.String()
}