Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/brutalist. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// CaptionImageBlockMeta defines the Captioned Image block.
|
|
var CaptionImageBlockMeta = blocks.BlockMeta{
|
|
Key: "caption_image",
|
|
Title: "Captioned Image",
|
|
Description: "Image with 11px mono caption in the left gutter",
|
|
Category: blocks.CategoryContent,
|
|
Source: "brutalist",
|
|
}
|
|
|
|
// CaptionImageData carries data for the caption-image component.
|
|
type CaptionImageData struct {
|
|
ImageURL string
|
|
Caption string
|
|
FigureNumber string
|
|
}
|
|
|
|
// CaptionImageBlock renders the captioned image.
|
|
// Content: {"image": "media:<id>", "caption": "...", "figureNumber": "Fig. 01"}
|
|
func CaptionImageBlock(ctx context.Context, content map[string]any) string {
|
|
img := getString(content, "image")
|
|
resolvedImage := ""
|
|
if img != "" {
|
|
resolvedImage = blocks.ResolveMediaPath(img)
|
|
}
|
|
|
|
data := CaptionImageData{
|
|
ImageURL: resolvedImage,
|
|
Caption: getString(content, "caption"),
|
|
FigureNumber: getString(content, "figureNumber"),
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = captionImageComponent(data).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|