{{/* Hugo Blox: Buttons */}} {{/* 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 }}
{{ $buttons_raw := index $content "buttons" }} {{ $buttons := slice }} {{ if reflect.IsSlice $buttons_raw }} {{ $buttons = $buttons_raw }} {{ else if and $buttons_raw (reflect.IsMap $buttons_raw) }} {{ $buttons = slice $buttons_raw }} {{ else if eq (printf "%T" $buttons_raw) "string" }} {{ $buttons = slice (dict "url" $buttons_raw) }} {{ end }} {{ range $index, $item := $buttons }} {{ $text := "" }} {{ $url := "" }} {{ $icon := "" }} {{ $new_tab := false }} {{ if reflect.IsMap $item }} {{ $text_raw := index $item "text" | default (index $item "label") | default (index $item "name") }} {{ if ne $text_raw nil }}{{ $text = strings.TrimSpace (printf "%v" $text_raw) }}{{ end }} {{ $url_raw := index $item "url" | default (index $item "link") }} {{ if eq (printf "%T" $url_raw) "string" }}{{ $url = strings.TrimSpace $url_raw }}{{ end }} {{ $icon_raw := index $item "icon" }} {{ if eq (printf "%T" $icon_raw) "string" }}{{ $icon = $icon_raw }}{{ end }} {{ $new_tab = partial "functions/coerce_bool" (dict "value" (index $item "new_tab") "default" false) }} {{ else if eq (printf "%T" $item) "string" }} {{ $url = strings.TrimSpace $item }} {{ end }} {{ if and (not $text) $url }} {{ $text = $url }} {{ end }} {{ if $url }} {{ $link := $url }} {{ $target := "" }} {{ $scheme := (urls.Parse $link).Scheme }} {{ if not $scheme }} {{ if not (hasPrefix $link "#") }} {{ $link = $link | relLangURL }} {{ end }} {{ if eq (path.Ext $link) ".pdf" }} {{ $new_tab = true }} {{ end }} {{ else if in (slice "http" "https") $scheme }} {{ $new_tab = true }} {{ end }} {{ if $new_tab }} {{ $target = "target=\"_blank\" rel=\"noopener noreferrer\"" }} {{ end }}
{{ with $icon }} {{ partial "functions/get_icon" (dict "name" . "attributes" "height=\"40\" width=\"40\" class=\"rounded-sm\"") }} {{ end }}
{{ $text | markdownify | emojify }}
{{ end }} {{ end }}