package main import ( "bytes" "context" "time" "git.dev.alexdunmow.com/block/core/blocks" ) // HoursStripBlockMeta defines metadata for the hours_strip block. var HoursStripBlockMeta = blocks.BlockMeta{ Key: "hours_strip", Title: "Hours Strip", Description: "Weekly hours strip with today's row server-side highlighted", Source: "coffee", } // HoursStripBlock renders a weekly hours strip. // Content shape: // // { // "todayLabel": "Today", // "hours": [ // {"day": "Mon", "open": "7:00", "close": "15:00"}, ... // ] // } // // The "today" row is detected server-side by comparing each row's day to the // current local weekday — no JS required. func HoursStripBlock(ctx context.Context, content map[string]any) string { todayLabel := getString(content, "todayLabel") if todayLabel == "" { todayLabel = "Today" } today := shortDayName(time.Now()) rawHours := getSlice(content, "hours") var rows []HoursRow for _, h := range rawHours { day := normaliseDay(getString(h, "day")) rows = append(rows, HoursRow{ Day: day, Open: getString(h, "open"), Close: getString(h, "close"), IsToday: day != "" && day == today, }) } data := HoursStripData{ TodayLabel: todayLabel, Rows: rows, } var buf bytes.Buffer _ = hoursStripComponent(data).Render(ctx, &buf) return buf.String() } // HoursStripData contains data for the hours strip component. type HoursStripData struct { TodayLabel string Rows []HoursRow } // HoursRow represents one weekday's hours. type HoursRow struct { Day string Open string Close string IsToday bool }