themes-art-deco/image_override.go
Alex Dunmow 9fbedf5ba1 initial: theme plugin art-deco
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/art-deco.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:11:19 +08:00

44 lines
1.0 KiB
Go

package main
import (
"bytes"
"context"
)
// ImageOverrideData is the typed view for the image override component.
type ImageOverrideData struct {
Src string
Alt string
Caption string
Frame string
}
// normaliseImageFrame clamps the frame option to the supported set.
func normaliseImageFrame(v string) string {
switch v {
case "stepped", "scallop", "plain":
return v
default:
return "stepped"
}
}
// ArtDecoImageBlock overrides the built-in "image" block when the Art Deco theme is active.
// Content: {"src": "...", "alt": "...", "caption": "...", "frame": "stepped|scallop|plain"}
func ArtDecoImageBlock(ctx context.Context, content map[string]any) string {
data := ImageOverrideData{
Src: getString(content, "src"),
Alt: getString(content, "alt"),
Caption: getString(content, "caption"),
Frame: normaliseImageFrame(getString(content, "frame")),
}
if data.Src == "" {
data.Src = fallbackImage()
}
var buf bytes.Buffer
_ = artDecoImageComponent(data).Render(ctx, &buf)
return buf.String()
}