Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/noir. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// LightboxGalleryBlockMeta defines the Noir lightbox gallery block.
|
|
var LightboxGalleryBlockMeta = blocks.BlockMeta{
|
|
Key: "lightbox_gallery",
|
|
Title: "Lightbox Gallery",
|
|
Description: "Grid of photographs that expand into a full-viewport lightbox overlay on click.",
|
|
Source: "noir",
|
|
Category: blocks.CategoryContent,
|
|
}
|
|
|
|
// LightboxGalleryBlock renders the gallery from content.items + content.columns.
|
|
// Content shape: {"items":[{"image":"...","caption":"..."}, ...], "columns": 2|3|4}
|
|
func LightboxGalleryBlock(ctx context.Context, content map[string]any) string {
|
|
items := getSlice(content, "items")
|
|
cols := getInt(content, "columns", 3)
|
|
if cols != 2 && cols != 3 && cols != 4 {
|
|
cols = 3
|
|
}
|
|
|
|
var entries []LightboxItem
|
|
for _, item := range items {
|
|
entries = append(entries, LightboxItem{
|
|
Image: blocks.ResolveMediaPath(getString(item, "image")),
|
|
Caption: getString(item, "caption"),
|
|
})
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = lightboxGalleryComponent(entries, cols).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// LightboxItem represents one photograph in the gallery.
|
|
type LightboxItem struct {
|
|
Image string
|
|
Caption string
|
|
}
|