package main import ( "bytes" "context" "git.dev.alexdunmow.com/block/core/blocks" ) // TracklistBlockMeta declares the CD-jewel-case tracklist block. var TracklistBlockMeta = blocks.BlockMeta{ Key: "tracklist", Title: "Tracklist", Description: "Tabular tracklist styled like a CD jewel case insert.", Source: "y2k", Category: blocks.CategoryContent, } // TracklistBlock renders the tracklist. // Content: {tracks[{title, duration, url}]} func TracklistBlock(ctx context.Context, content map[string]any) string { raw := getSlice(content, "tracks") tracks := make([]TrackRow, 0, len(raw)) for _, r := range raw { tracks = append(tracks, TrackRow{ Title: getString(r, "title"), Duration: getString(r, "duration"), URL: getString(r, "url"), }) } var buf bytes.Buffer _ = tracklistComponent(TracklistData{Tracks: tracks}).Render(ctx, &buf) return buf.String() } // TracklistData is the typed shape for the templ component. type TracklistData struct { Tracks []TrackRow } // TrackRow is a single tracklist row. type TrackRow struct { Title string Duration string URL string }