feat(shortcode): fix Gallery captions + support Markdown in captions

Fixes image captions when the Gallery shortcode is used on Widget Pages.
The issue was caused by a path mismatch in the code.

Adds support for using Markdown and emojis in image gallery captions.

Close #1136 - the bug report.
This commit is contained in:
George Cushen committed 2019-06-16 19:10:49 +01:00
1 parent 0c36cdca45
commit d33d6b0ff6
1 file changed
+6 -6
+6 -6
View File
@@ -21,14 +21,14 @@
{{ range $images }}
{{ $image := .Resize "x190" }}
{{/* Check if the user set a caption for this image */}}
{{ $filename := .Name }}
{{ $filename := path.Base .Name }}
{{ $caption := "" }}
{{ if $.Page.Params.gallery_item }}
{{ range (where $.Page.Params.gallery_item "album" $album) }}
{{if eq (printf "%s/%s" $album .image) $filename}}{{ with .caption }}{{ $caption = . }}{{end}}{{end}}
{{ range (where (where $.Page.Params.gallery_item "album" $album) "image" $filename) }}
{{ $caption = .caption }}
{{ end }}
{{ end }}
{{ end }}
<a data-fancybox="gallery-{{$album}}" href="{{ .RelPermalink }}" {{ with $caption }}data-caption="{{.}}"{{ end }}>
<a data-fancybox="gallery-{{$album}}" href="{{ .RelPermalink }}" {{ with $caption }}data-caption="{{.|markdownify|emojify|safeHTMLAttr}}"{{ end }}>
<img src="{{ $image.RelPermalink }}" alt="">
</a>
{{end}}
@@ -45,7 +45,7 @@
{{ $.Scratch.Set "src" (printf "img/%s" .image | relURL) }}
{{ end }}
{{ end }}
<a data-fancybox="gallery{{ with .album }}-{{.}}{{ end }}" {{ with .caption }}data-caption="{{.}}"{{ end }} href="{{$.Scratch.Get "src"}}">
<a data-fancybox="gallery{{ with .album }}-{{.}}{{ end }}" {{ with .caption }}data-caption="{{.|markdownify|emojify|safeHTMLAttr}}"{{ end }} href="{{$.Scratch.Get "src"}}">
<img src="{{$.Scratch.Get "src"}}" alt="">
</a>
{{end}}