diff --git a/exampleSite/content/docs/shortcodes/index.md b/exampleSite/content/docs/shortcodes/index.md
index d5bf0d60..0ace0305 100644
--- a/exampleSite/content/docs/shortcodes/index.md
+++ b/exampleSite/content/docs/shortcodes/index.md
@@ -251,10 +251,13 @@ Call to action
| Parameter | Description |
| --- | --- |
| `images` | **Required.** A regex string to match image names or URLs. |
+| `captions` | **Optional.** A list of `key:caption` pairs. Keys can be image filenames (for local images) or full URLs (for remote images). |
| `aspectRatio` | **Optional.** The aspect ratio for the carousel. It is set to `16-9` by default. |
| `interval` | **Optional.** The interval for the auto-scrooling, specified in milliseconds. Defaults to `2000` (2s) |
+Captions are matched by key. For local images, use the filename (e.g. `01.jpg`). For remote images, use the full URL.
+
**Example 1:** 16:9 aspect ratio and verbose list of images
```md
@@ -271,6 +274,14 @@ Call to action
{{< carousel images="gallery/*" aspectRatio="21-9" interval="2500" >}}
+**Example 3:** Add captions
+
+```md
+{{* carousel images="gallery/*" captions="{01.jpg:First image,02.jpg:Second image}" */>}}
+```
+
+{{< carousel images="gallery/*" captions="{01.jpg:First image,02.jpg:Second image}" >}}
+
## Chart
diff --git a/layouts/shortcodes/carousel.html b/layouts/shortcodes/carousel.html
index db401e21..64f6d728 100644
--- a/layouts/shortcodes/carousel.html
+++ b/layouts/shortcodes/carousel.html
@@ -1,7 +1,7 @@
{{ $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") }}
{{ $page := .Page.Resources }}
@@ -11,13 +11,29 @@
{{ $imagesTemp := strings.Split $imagesTemp "," }}
{{ $images := slice }}
{{ range $imagesTemp }}
- {{ if or (strings.HasPrefix . "http:") (strings.HasPrefix . "https:") }}
- {{ $images = $images | append (resources.GetRemote .) }}
- {{ else }}
- {{ $images = $images | append ($page.Match .) }}
- {{ end }}
+{{ 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 }}
{{ 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 }}
+{{ end }}
{{ if not .Parent }}