Просмотр исходного кода

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.
George Cushen 6 лет назад
Родитель
Сommit
d33d6b0ff6
1 измененных файлов с 6 добавлено и 6 удалено
  1. 6 6
      layouts/shortcodes/gallery.html

+ 6 - 6
layouts/shortcodes/gallery.html

@@ -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}}