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>
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// MarginaliaBlockMeta describes the Editorial marginalia rail block: a list of
|
|
// italic notes anchored to in-body markers. At narrow viewports the rail
|
|
// collapses to inline asides via CSS.
|
|
// Registered as "editorial:marginalia" at runtime.
|
|
var MarginaliaBlockMeta = blocks.BlockMeta{
|
|
Key: "marginalia",
|
|
Title: "Marginalia Rail",
|
|
Description: "Right-rail italic notes for longform articles",
|
|
Source: "editorial",
|
|
Category: blocks.CategoryTheme,
|
|
}
|
|
|
|
// MarginaliaNote is one row in the marginalia rail.
|
|
type MarginaliaNote struct {
|
|
Note string // rich-text payload
|
|
Anchor string
|
|
}
|
|
|
|
// MarginaliaData carries parsed marginalia content.
|
|
type MarginaliaData struct {
|
|
Notes []MarginaliaNote
|
|
}
|
|
|
|
// MarginaliaBlock renders the marginalia rail.
|
|
//
|
|
// Content shape:
|
|
//
|
|
// {
|
|
// "items": [
|
|
// { "note": "<p>Sourced from the 2024 audit.</p>", "anchor": "¶3" }
|
|
// ]
|
|
// }
|
|
func MarginaliaBlock(ctx context.Context, content map[string]any) string {
|
|
items := getSlice(content, "items")
|
|
|
|
notes := make([]MarginaliaNote, 0, len(items))
|
|
for _, item := range items {
|
|
notes = append(notes, MarginaliaNote{
|
|
Note: getString(item, "note"),
|
|
Anchor: getString(item, "anchor"),
|
|
})
|
|
}
|
|
|
|
data := MarginaliaData{Notes: notes}
|
|
|
|
var buf bytes.Buffer
|
|
_ = marginaliaComponent(data).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|