{{/* Hugo Blox: Stats */}} {{/* Documentation: https://hugoblox.com/blocks/ */}} {{/* License: https://github.com/HugoBlox/kit/blob/main/LICENSE.md */}} {{/* Initialise */}} {{ $page := .wcPage }} {{ $block := .wcBlock }} {{ $content := $block.content }} {{ if not (reflect.IsMap $content) }}{{ $content = dict }}{{ end }} {{ $design := $block.design }} {{ if not (reflect.IsMap $design) }}{{ $design = dict }}{{ end }} {{ $title := "" }} {{ $title_raw := index $content "title" }} {{ if $title_raw }} {{ $title = strings.TrimSpace (printf "%v" $title_raw) }} {{ end }} {{ if $title }}{{ $title = $title | emojify | $page.RenderString }}{{ end }} {{ $text := "" }} {{ $text_raw := index $content "text" }} {{ if $text_raw }} {{ $text = strings.TrimSpace (printf "%v" $text_raw) }} {{ end }} {{ if $text }}{{ $text = $text | emojify | $page.RenderString }}{{ end }} {{ $layout := "cards" }} {{ $layout_raw := index $design "layout" }} {{ if eq (printf "%T" $layout_raw) "string" }} {{ $layout_candidate := lower (strings.TrimSpace $layout_raw) }} {{ if in (slice "cards" "compact" "minimal") $layout_candidate }} {{ $layout = $layout_candidate }} {{ end }} {{ end }} {{ $items_raw := index $content "items" }} {{ $items_iter := slice }} {{ if reflect.IsSlice $items_raw }} {{ $items_iter = $items_raw }} {{ else if and $items_raw (reflect.IsMap $items_raw) }} {{ $items_iter = slice $items_raw }} {{ end }} {{ $items := slice }} {{ if gt (len $items_iter) 0 }} {{ range $items_iter }} {{ if reflect.IsMap . }} {{ $icon := "" }} {{ $statistic := "" }} {{ $description := "" }} {{ $sub_metric := "" }} {{ with index . "icon" }}{{ $icon = printf "%v" . }}{{ end }} {{ with index . "statistic" }}{{ $statistic = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index . "description" }}{{ $description = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index . "sub_metric" }}{{ $sub_metric = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ if or $statistic $description }} {{ $items = $items | append (dict "icon" $icon "statistic" $statistic "description" $description "sub_metric" $sub_metric) }} {{ end }} {{ end }} {{ end }} {{ end }} {{ $item_count := len $items }} {{ if lt $item_count 1 }}{{ $item_count = 1 }}{{ end }} {{ if gt $item_count 4 }}{{ $item_count = 4 }}{{ end }} {{ $grid_cols_class := "lg:grid-cols-3" }} {{ if eq $item_count 1 }} {{ $grid_cols_class = "lg:grid-cols-1" }} {{ else if eq $item_count 2 }} {{ $grid_cols_class = "lg:grid-cols-2" }} {{ else if eq $item_count 4 }} {{ $grid_cols_class = "lg:grid-cols-4" }} {{ end }} {{ $base_cols_class := "grid-cols-2" }} {{ if eq $item_count 1 }}{{ $base_cols_class = "grid-cols-1" }}{{ end }}
{{ . }}
{{ end }}{{ (index $item "description") | $page.RenderString }}
{{/* Optional Sub-metric */}} {{ with index $item "sub_metric" }}{{ . }}
{{ end }}{{ (index $item "description") | $page.RenderString }}
{{ (index $item "description") | $page.RenderString }}