{{/* Hugo Blox: CTA Image Paragraph */}} {{/* 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 }}
{{ $items_raw := index $content "items" }} {{ $items := slice }} {{ if reflect.IsSlice $items_raw }} {{ $items = $items_raw }} {{ else if and $items_raw (reflect.IsMap $items_raw) }} {{ $items = slice $items_raw }} {{ end }} {{ range $idx, $item := $items }} {{ if reflect.IsMap $item }} {{ $title := "" }} {{ $title_raw := index $item "title" }} {{ if eq (printf "%T" $title_raw) "string" }}{{ $title = $title_raw | emojify | $page.RenderString }}{{ end }} {{ $text := "" }} {{ $text_raw := index $item "text" }} {{ if eq (printf "%T" $text_raw) "string" }}{{ $text = $text_raw | emojify | $page.RenderString }}{{ end }} {{ $image_name := "" }} {{ $image_raw := index $item "image" }} {{ if eq (printf "%T" $image_raw) "string" }}{{ $image_name = strings.TrimSpace $image_raw }}{{ end }} {{/* Resolve image from page bundle, site assets, remote, or static URLs */}} {{ $image_resource := false }} {{ $image_url := "" }} {{ $image_path := "" }} {{ if $image_name }} {{ $image_path = strings.TrimSpace (printf "%v" $image_name) }} {{ $is_remote := or (strings.HasPrefix $image_path "http://") (strings.HasPrefix $image_path "https://") }} {{ if $is_remote }} {{ $remote := try (resources.GetRemote $image_path) }} {{ if and $remote (not $remote.Err) }} {{ $image_resource = $remote.Value }} {{ else }} {{ $image_url = $image_path }} {{ end }} {{ else }} {{ $image_path = strings.TrimPrefix "/" $image_path }} {{ $image_path = strings.TrimPrefix "./" $image_path }} {{ $image_path = strings.TrimPrefix "assets/" $image_path }} {{ $image_path = strings.TrimPrefix "media/" $image_path }} {{ $normalized := path.Clean $image_path }} {{ if and $normalized (ne $normalized ".") }} {{ with $page }} {{ $image_resource = (.Resources.ByType "image").GetMatch $normalized }} {{ end }} {{ if not $image_resource }} {{ $image_resource = resources.Get (path.Join "media" $normalized) }} {{ end }} {{ if not $image_resource }} {{ $image_url = printf "/media/%s" $normalized }} {{ end }} {{ end }} {{ end }} {{ end }} {{ $image_to_render := $image_resource }} {{ if $image_to_render }}
{{ if ne $image_to_render.MediaType.SubType "gif" }} {{ $responsive := partial "functions/process_responsive_image.html" (dict "image" $image_to_render "mode" "fit" "sizes" (slice 400 600 800 1200) ) }} {{$title | plainify}} {{ else }} {{$title | plainify}} {{ end }}
{{ else if $image_url }}
{{ $is_external := or (strings.HasPrefix $image_url "http://") (strings.HasPrefix $image_url "https://") }} {{$title | plainify}}
{{ else }} {{ warnf "%s uses the `cta-image-paragraph` blox which specifies a non-existent `image` at `assets/%s`. Skipping this item." $page.File.Path $image_path }} {{ end }}

{{$title}}

{{$text}}

{{ $icon := "check" }} {{ $icon_raw := index $item "feature_icon" }} {{ if eq (printf "%T" $icon_raw) "string" }}{{ $icon = $icon_raw }}{{ end }} {{ $features_raw := index $item "features" }} {{ $features := slice }} {{ if reflect.IsSlice $features_raw }} {{ $features = $features_raw }} {{ else if eq (printf "%T" $features_raw) "string" }} {{ $features = slice $features_raw }} {{ end }} {{ if gt (len $features) 0 }} {{ end }} {{ $button_raw := index $item "button" }} {{ if and $button_raw (reflect.IsMap $button_raw) }} {{ $button_text := "" }} {{ $button_url := "" }} {{ with index $button_raw "text" }}{{ $button_text = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ with index $button_raw "url" }}{{ $button_url = strings.TrimSpace (printf "%v" .) }}{{ end }} {{ if and $button_text $button_url }} {{ $link := $button_url }} {{ $target := "" }} {{ $scheme := (urls.Parse $link).Scheme }} {{ if not $scheme }} {{ if not (hasPrefix $link "#") }} {{ $link = $link | relLangURL }} {{ end }} {{ if eq (path.Ext $link) ".pdf" }}{{ $target = "target=\"_blank\" rel=\"noopener\"" }}{{ end }} {{ else if in (slice "http" "https") $scheme }} {{ $target = "target=\"_blank\" rel=\"noopener\"" }} {{ end }} {{ $button_text }} {{ end }} {{ end }}
{{ end }} {{ end }}