59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// FeaturesBlockMeta defines metadata for the features grid block.
|
|
var FeaturesBlockMeta = blocks.BlockMeta{
|
|
Key: "features",
|
|
Title: "Feature Cards",
|
|
Description: "Grid of feature cards with icons and descriptions",
|
|
Source: "gotham",
|
|
}
|
|
|
|
// FeaturesBlock renders a feature cards grid.
|
|
// Content expects: {"section_title": "...", "columns": 3, "features": [{"icon": "...", "title": "...", "description": "..."}]}
|
|
func FeaturesBlock(ctx context.Context, content map[string]any) string {
|
|
items := getSlice(content, "features")
|
|
if len(items) == 0 {
|
|
return ""
|
|
}
|
|
|
|
var features []FeatureItem
|
|
for _, item := range items {
|
|
features = append(features, FeatureItem{
|
|
Icon: getString(item, "icon"),
|
|
Title: getString(item, "title"),
|
|
Description: getString(item, "description"),
|
|
})
|
|
}
|
|
|
|
data := FeaturesData{
|
|
SectionTitle: getString(content, "section_title"),
|
|
Columns: getInt(content, "columns", 3),
|
|
Features: features,
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = featuresComponent(data).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// FeaturesData contains data for the features component.
|
|
type FeaturesData struct {
|
|
SectionTitle string
|
|
Columns int
|
|
Features []FeatureItem
|
|
}
|
|
|
|
// FeatureItem represents a single feature.
|
|
type FeatureItem struct {
|
|
Icon string
|
|
Title string
|
|
Description string
|
|
}
|