Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/coffee. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
92 lines
2.1 KiB
Go
92 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// getString extracts a string value from content map.
|
|
func getString(content map[string]any, key string) string {
|
|
if v, ok := content[key].(string); ok {
|
|
return v
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// getBool extracts a bool value from content map (handles string forms).
|
|
func getBool(content map[string]any, key string, defaultVal bool) bool {
|
|
if v, ok := content[key].(bool); ok {
|
|
return v
|
|
}
|
|
if v, ok := content[key].(string); ok {
|
|
switch strings.ToLower(v) {
|
|
case "true", "yes", "1":
|
|
return true
|
|
case "false", "no", "0":
|
|
return false
|
|
}
|
|
}
|
|
return defaultVal
|
|
}
|
|
|
|
// getSlice extracts a slice of maps from content.
|
|
func getSlice(content map[string]any, key string) []map[string]any {
|
|
if v, ok := content[key].([]any); ok {
|
|
result := make([]map[string]any, 0, len(v))
|
|
for _, item := range v {
|
|
if m, ok := item.(map[string]any); ok {
|
|
result = append(result, m)
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// shortDayName returns the three-letter weekday abbreviation for "today" in
|
|
// the server's local time zone. Used by hours_strip to flag today's row
|
|
// server-side (no JS).
|
|
func shortDayName(now time.Time) string {
|
|
switch now.Weekday() {
|
|
case time.Monday:
|
|
return "Mon"
|
|
case time.Tuesday:
|
|
return "Tue"
|
|
case time.Wednesday:
|
|
return "Wed"
|
|
case time.Thursday:
|
|
return "Thu"
|
|
case time.Friday:
|
|
return "Fri"
|
|
case time.Saturday:
|
|
return "Sat"
|
|
case time.Sunday:
|
|
return "Sun"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// normaliseDay accepts a free-form day string and returns the matching short
|
|
// name. This lets editors enter "Monday", "mon", or "Mon" and still get a
|
|
// reliable comparison against today.
|
|
func normaliseDay(day string) string {
|
|
d := strings.ToLower(strings.TrimSpace(day))
|
|
switch {
|
|
case strings.HasPrefix(d, "mon"):
|
|
return "Mon"
|
|
case strings.HasPrefix(d, "tue"):
|
|
return "Tue"
|
|
case strings.HasPrefix(d, "wed"):
|
|
return "Wed"
|
|
case strings.HasPrefix(d, "thu"):
|
|
return "Thu"
|
|
case strings.HasPrefix(d, "fri"):
|
|
return "Fri"
|
|
case strings.HasPrefix(d, "sat"):
|
|
return "Sat"
|
|
case strings.HasPrefix(d, "sun"):
|
|
return "Sun"
|
|
}
|
|
return strings.TrimSpace(day)
|
|
}
|