themes-terminal/footer.go
Alex Dunmow 0a9b177f7c initial: theme plugin terminal
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/terminal.

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

60 lines
1.4 KiB
Go

package main
import (
"bytes"
"context"
"git.dev.alexdunmow.com/block/core/blocks"
)
// FooterBlockMeta defines metadata for the TTY footer block.
var FooterBlockMeta = blocks.BlockMeta{
Key: "footer",
Title: "TTY Footer",
Description: "EOF rule, MOTD, optional newsletter signup",
Source: "terminal",
Category: blocks.CategoryLayout,
}
// FooterLink is a single footer link.
type FooterLink struct {
Label string
URL string
}
// FooterData is the parsed content for the footer block.
type FooterData struct {
Motd string
Links []FooterLink
ShowSignup bool
}
// FooterBlock renders the TTY footer.
// Content shape: {motd, links[{label, url}], showSignup}.
func FooterBlock(ctx context.Context, content map[string]any) string {
links := getSlice(content, "links")
footerLinks := make([]FooterLink, 0, len(links))
for _, l := range links {
footerLinks = append(footerLinks, FooterLink{
Label: getString(l, "label"),
URL: getString(l, "url"),
})
}
// showSignup tolerates bool, string "true", or select "true"/"false".
signup := getBool(content, "showSignup")
if !signup {
if s := getString(content, "showSignup"); s == "true" {
signup = true
}
}
data := FooterData{
Motd: getStringDefault(content, "motd", "connection closed."),
Links: footerLinks,
ShowSignup: signup,
}
var buf bytes.Buffer
_ = footerComponent(data).Render(ctx, &buf)
return buf.String()
}