themes-kindergarten/alphabet_strip.go
Alex Dunmow ffe46a146c initial: theme plugin kindergarten
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/kindergarten.

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

65 lines
1.5 KiB
Go

package main
import (
"bytes"
"context"
"strings"
"git.dev.alexdunmow.com/block/core/blocks"
)
// AlphabetStripBlockMeta defines metadata for the alphabet strip block.
var AlphabetStripBlockMeta = blocks.BlockMeta{
Key: "alphabet_strip",
Title: "Alphabet Strip",
Description: "Decorative letter band; jumps to anchors when used as TOC.",
Category: blocks.CategoryNavigation,
Source: "kindergarten",
}
// AlphabetStripData contains the letters + colorway for the rendered strip.
type AlphabetStripData struct {
Letters []string
ColorMode string
}
// AlphabetStripBlock renders a decorative letter band.
// Content shape: {letters,colorMode}.
func AlphabetStripBlock(ctx context.Context, content map[string]any) string {
raw := getStringDefault(content, "letters", "")
colorMode := getStringDefault(content, "colorMode", "rainbow")
// Validate colorMode against allowed set.
switch colorMode {
case "primary", "rainbow", "mono":
default:
colorMode = "rainbow"
}
letters := splitLetters(raw)
data := AlphabetStripData{
Letters: letters,
ColorMode: colorMode,
}
var buf bytes.Buffer
_ = alphabetStripComponent(data).Render(ctx, &buf)
return buf.String()
}
// splitLetters returns one entry per visible rune. Whitespace is trimmed.
func splitLetters(s string) []string {
s = strings.TrimSpace(s)
if s == "" {
return nil
}
letters := make([]string, 0, len(s))
for _, r := range s {
if r == ' ' || r == '\t' || r == '\n' {
continue
}
letters = append(letters, string(r))
}
return letters
}