Gallery caption from txt files

Dear Hugo fans!

I would like to build an image gallery (based on the new Resources) without any trance in the source code of the index.md file.

Images are no problem:

{{ with .Resources.Match "gallery-image*" }}
  <div class="gallery">
    {{ range . }}
    {{ $image := .Fill "400x400" }}
    <figure><img src="{{ $image.RelPermalink }}" alt="&nbsp;"></figure>
    {{ end }}
  </div>
{{ end }}

But how is it possible to add captions. My idea is to use seperate .txt files containing the captions:

── blog-article/
│   └── gallery-caption01.txt
│   └── gallery-image01.jpg
│   └── gallery-image02.jpg
│   └── gallery-caption03.txt
│   └── gallery-image03.jpg
│   └── index.md

Reading them is not possible this way:

{{ range .Resources.Match "gallery-caption*" }}
{{ .RelPermalink | readFile | safeHTML }}
{{ end }}

For readFile you obviously need to point to the source (content/blogname/blog-article) of the txt files. RelPermalink or Permalink does not work.

And how do you combine the ranges, so that Hugo reads the content of gallery-caption03.txt only within the range for gallery-image03.txt.

Thank you very much!

Hugo 0.33 has made it possible to add metadata to .Resources images. I haven’t had a chance to check it out myself yet, but here are the release notes:https://gohugo.io/news/0.33-relnotes/

Thank you. That is an easy and clever way.

[[resources]]
src = "gallery-03.jpg"
[resources.params]
caption = "My caption"

I am pretty close to a working version with txt files for caption, which I would prefer.

{{ $imageName := replaceRE ".[^.]*$" "$1*" .Name }}
{{ range ($.Resources.ByType "plain").Match $imageName }}
{{ . }}
{{ end }}

{{ . }}} puts out name, title and the correct absolute of the source. Does anyone know how to access the absolute path. {{ .SRC }} etc. do not work.

With the correct path readFile will work.

Thanks