resources.GetMatch gets different file format

I am playing around with my figure shortcode, trying to over-optimize everything, and am experiencing a weird situation.

The frontmatter:

resources:
    - src: "celebrating-the-national-theatre-6753651837108751-2x.png"
      name: "the-national-theatre"
      title: "The National Theatre"

The call to the shortcode:

{{< figure name="the-national-theatre" >}}{{< /figure >}}

The part of the shortcode that calls the file:

{{ $image := .Page.Resources.GetMatch (printf "*%s*" (.Get "name")) }}

The result $image, debugged:

Name			"celebrating-the-national-theatre-6753651837108751-2x.webp"
Title			"celebrating-the-national-theatre-6753651837108751-2x.webp"
ResourceType	"image"
Permalink		"//localhost:1313/2020/12/google-doodle-des-tages-national-theater/celebrating-the-national-theatre-6753651837108751-2x.webp"
RelPermalink	"/2020/12/google-doodle-des-tages-national-theater/celebrating-the-national-theatre-6753651837108751-2x.webp"

The foldercontent:

index.md < the file with the frontmatter and shortcode call
celebrating-the-national-theatre-6753651837108751-2x.webp
celebrating-the-national-theatre-6753651837108751-2x.png

Now… I would expect, because I explicitly state the name of the resource, that Hugo returns the PNG image to me. Note, that I do NOT define resource info for the webp file. That file is just there (for future purposes).

What might be the reason that Hugo is returning the webp file name?

Little update: I added some characters to the name so it’s not something that is part of both filenames and GetMatch works as expected. It looks like the match is happening in name AND filename and somehow the webp resource gets listed first (if I iterate over all resources) so it gets returned with GetMatch.

Name defaults to filename if not set: Page Resources | Hugo

Oh I get it… I think. Because the webp file has no name it’s the filename and that matches *the-national-theatre* and is the first item.

Makes sense now.

I probably should check first for the-national-theatre before testing as fallback for *the-national-theatre*.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.