From 3dd3d0fae841ac77ddf7304b74025193d1bc21f9 Mon Sep 17 00:00:00 2001 From: Alex Haslam Date: Fri, 6 Feb 2026 13:06:58 +0000 Subject: [PATCH] Make captions move --- layouts/shortcodes/carousel.html | 128 +++++++++++++++---------------- 1 file changed, 62 insertions(+), 66 deletions(-) diff --git a/layouts/shortcodes/carousel.html b/layouts/shortcodes/carousel.html index 64f6d728..9f3cd004 100644 --- a/layouts/shortcodes/carousel.html +++ b/layouts/shortcodes/carousel.html @@ -1,93 +1,75 @@ {{ $id := delimit (slice "carousel" (partial "functions/uid.html" .) (now.UnixNano)) "-" }} {{ $aspect := (split (.Get "aspectRatio") "-") }} -{{ $aspectx := default "16" (index $aspect 0) }} -{{ $aspecty := default "9" (index $aspect 1) }} +{{ $aspectx := default "16" (index $aspect 0) }} +{{ $aspecty := default "9" (index $aspect 1) }} {{ $interval := default "2000" (.Get "interval") }} +{{ $imagesParam := .Get "images" }} +{{ $items := slice }} {{ $page := .Page.Resources }} -{{ $imagesTemp := .Get "images" }} +{{ $imagesTemp := $imagesParam }} {{ $imagesTemp = strings.TrimPrefix "{" $imagesTemp }} {{ $imagesTemp = strings.TrimSuffix "}" $imagesTemp }} {{ $imagesTemp := strings.Split $imagesTemp "," }} -{{ $images := slice }} {{ range $imagesTemp }} -{{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} -{{ $images = $images | append (dict "resource" (resources.GetRemote .) "key" .) }} -{{ else }} -{{ range ($page.Match .) }} -{{ $images = $images | append (dict "resource" . "key" .Name) }} -{{ end }} -{{ end }} + {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }} + {{ $items = $items | append (dict "resource" (resources.GetRemote .) "key" .) }} + {{ else }} + {{ range ($page.Match .) }} + {{ $items = $items | append (dict "resource" . "key" .Name) }} + {{ end }} + {{ end }} {{ end }} {{ $captionsParam := .Get "captions" }} {{ $captions := dict }} {{ if $captionsParam }} -{{ $captionsTemp := strings.TrimPrefix "{" $captionsParam }} -{{ $captionsTemp = strings.TrimSuffix "}" $captionsTemp }} -{{ range (strings.Split $captionsTemp ",") }} -{{ $pair := strings.Split . ":" }} -{{ if ge (len $pair) 2 }} -{{ $key := strings.TrimSpace (index $pair 0) }} -{{ $value := strings.TrimSpace (delimit (after 1 $pair) ":") }} -{{ $captions = merge $captions (dict $key $value) }} -{{ end }} -{{ end }} + {{ $captionsTemp := strings.TrimPrefix "{" $captionsParam }} + {{ $captionsTemp = strings.TrimSuffix "}" $captionsTemp }} + {{ range (strings.Split $captionsTemp ",") }} + {{ $pair := strings.Split . ":" }} + {{ if ge (len $pair) 2 }} + {{ $key := strings.TrimSpace (index $pair 0) }} + {{ $value := strings.TrimSpace (delimit (after 1 $pair) ":") }} + {{ $captions = merge $captions (dict $key $value) }} + {{ end }} + {{ end }} {{ end }} {{ if not .Parent }}
{{ end }}
-
-
- {{ $num := 0 }} - {{ range $images }} - - {{ $num = add $num 1 }} - {{ end }} -
- -
- {{ range $index, $image := $images }} - {{ $hiddenClass := cond (eq $index 0) "" "hidden" }} - {{ $resource := index $image "resource" }} -
-
- carousel image {{ add $index 1 }} -
-
- {{ end }} -
+
+ {{ $num := 0 }} + {{ range $items }} + + {{ $num = add $num 1 }} + {{ end }}
-
- {{ range $index, $image := $images }} +
+ {{ range $index, $item := $items }} {{ $hiddenClass := cond (eq $index 0) "" "hidden" }} - {{ $resource := index $image "resource" }} - {{ $key := index $image "key" }} + {{ $resource := index $item "resource" }} + {{ $key := index $item "key" }} {{ $caption := "" }} {{ $candidates := slice }} {{ if $resource }} - {{ $candidates = $candidates | append $resource.Name (path.Base $resource.Name) $resource.RelPermalink (path.Base - $resource.RelPermalink) }} + {{ $candidates = $candidates | append $resource.Name (path.Base $resource.Name) $resource.RelPermalink (path.Base $resource.RelPermalink) }} {{ end }} {{ if $key }} {{ $candidates = $candidates | append $key (path.Base $key) }} @@ -98,10 +80,24 @@ {{ end }} {{ end }}
- {{ $caption | markdownify }} + class="relative float-left -mr-[100%] {{ $hiddenClass }} w-full transition-transform ease-in-out motion-reduce:transition-none" + data-twe-carousel-item + style="transition-duration: {{ $interval }}ms;" + {{ if eq $index 0 }}data-twe-carousel-active{{ end }}> +
+
+ carousel image {{ add $index 1 }} +
+ {{ if $caption }} +
{{ $caption | markdownify }}
+ {{ end }} +
{{ end }}