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

66 lines
1.5 KiB
Go

package main
import (
"bytes"
"context"
"git.dev.alexdunmow.com/block/core/blocks"
)
// ColophonBlockMeta describes the Editorial colophon (footer) block: optional
// subscribe stub, optional ISSN field, and a list of inline footer links.
// Registered as "editorial:colophon" at runtime.
var ColophonBlockMeta = blocks.BlockMeta{
Key: "colophon",
Title: "Colophon",
Description: "Editorial footer with ISSN, subscribe stub, and link list",
Source: "editorial",
Category: blocks.CategoryNavigation,
}
// ColophonLink is one row in the colophon link list.
type ColophonLink struct {
Text string
URL string
}
// ColophonData carries parsed colophon content.
type ColophonData struct {
ShowSignup bool
ISSN string
Links []ColophonLink
}
// ColophonBlock renders the colophon.
//
// Content shape:
//
// {
// "showSignup": "true",
// "issn": "0000-0000",
// "links": [
// { "text": "About", "url": "/about" },
// { "text": "Style Guide", "url": "/style-guide" }
// ]
// }
func ColophonBlock(ctx context.Context, content map[string]any) string {
rawLinks := getSlice(content, "links")
links := make([]ColophonLink, 0, len(rawLinks))
for _, l := range rawLinks {
links = append(links, ColophonLink{
Text: getString(l, "text"),
URL: getString(l, "url"),
})
}
data := ColophonData{
ShowSignup: getBool(content, "showSignup", false),
ISSN: getString(content, "issn"),
Links: links,
}
var buf bytes.Buffer
_ = colophonComponent(data).Render(ctx, &buf)
return buf.String()
}