Two and a half years ago @jmooring helped me to alter the build-in figure shortcode to use page ressources. This worked find at that time. I now wanted to update the website, but the build fails with:
$ hugo server -w
Watching for changes in /web/{archetypes,content,data,layouts,static,themes}
Watching for config changes in /web/config.toml
Start building sites …
hugo v0.121.1-00b46fed8e47f7bb0a85d7cfc2d9f1356379b740+extended linux/amd64 BuildDate=2023-12-08T08:47:45Z VendorInfo=snap:0.121.1
Built in 76 ms
Error: error building site: "/web/content/haeuser/weidelbach/index.md:56:1": failed to render shortcode "figure": failed to process shortcode: "/web/themes/gewoba/layouts/shortcodes/figure.html:2:19": execute of template failed: template: shortcodes/figure.html:2:19: executing "shortcodes/figure.html" at <$img.Params.Get>: Get is not a method but has arguments
The altered figure shortcode is:
{{ $img := $.Page.Resources.GetMatch (.Get "src")}}
<figure{{ with $img.Params.Get "class" }} class="{{ . }}"{{ end }} {{ with $img.Params.Get "width" }} style="width:calc({{ . }} - 4em - 32px);"{{ end }}>
{{- if $img.Params.Get "link" -}}
<a href="{{ $img.Params.Get "link" }}"{{ with $img.Params.Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>
{{- end }}
<img src="{{ $img.RelPermalink }}"
{{- if or ($img.Params.Get "alt") ($img.Params.Get "caption") }}
alt="{{ with $img.Params.Get "alt" }}{{ . }}{{ else }}{{ $img.Params.Get "caption" | markdownify| plainify }}{{ end }}"
{{- end -}}
width="100%"
{{- with $img.Params.Get "height" }} height="{{ . }}"{{ end -}}
/> <!-- Closing img tag -->
{{- if $img.Params.Get "link" }}</a>{{ end -}}
{{- if or (or ($img.Title) ($img.Params.Get "caption")) ($img.Params.Get "attr") -}}
<figcaption>
{{ with ($img.Title) -}}
<h4>{{ . }}</h4>
{{- end -}}
{{- if or ($img.Params.Get "caption") ($img.Params.Get "attr") -}}<p>
{{- $img.Params.Get "caption" | markdownify -}}
{{- with $img.Params.Get "attrlink" }}
<a href="{{ . }}">
{{- end -}}
{{- $img.Params.Get "attr" | markdownify -}}
{{- if $img.Params.Get "attrlink" }}</a>{{ end }}</p>
{{- end }}
</figcaption>
{{- end }}
</figure>
I’m wondering if I ran into the bug "is not a method but has arguments" error message is confusing · Issue #10862 · gohugoio/hugo · GitHub but I’m unfortuntely unable to understand what changes I do need to make. I appreciate any hint.