package main import ( "bytes" "context" "git.dev.alexdunmow.com/block/core/blocks" ) // TocBlockMeta defines metadata for the section TOC block. var TocBlockMeta = blocks.BlockMeta{ Key: "toc", Title: "Section TOC", Description: "Fixed left-rail table of contents for article pages", Source: "terminal", Category: blocks.CategoryNavigation, } // TocItem is a single TOC entry. type TocItem struct { Label string Anchor string } // TocData is the parsed content for the toc block. type TocData struct { Heading string Items []TocItem } // TocBlock renders the section TOC. // Content shape: {heading, items[{label, anchor}]}. func TocBlock(ctx context.Context, content map[string]any) string { items := getSlice(content, "items") tocItems := make([]TocItem, 0, len(items)) for _, it := range items { tocItems = append(tocItems, TocItem{ Label: getString(it, "label"), Anchor: getString(it, "anchor"), }) } data := TocData{ Heading: getStringDefault(content, "heading", "Sections"), Items: tocItems, } var buf bytes.Buffer _ = tocComponent(data).Render(ctx, &buf) return buf.String() }