regis
January 13, 2023, 4:13pm
1
I was never able to find the perfect glob pattern to find files at /image.jpg
and /down-dir/image.jpg
below the root dir.
I use /**/image.jpg
and it will find any files at any level of the tree, but not the files at the root.
So I end up doing two calls. resources.Match /image.jpg
and another resources.Match /**/image.jpg
**image.jpg
or /**image.jpg
does not workβ¦
Any body knows if a single pattern could find both files?
1 Like
content/
βββ posts/
β βββ post-1/
β βββ page_resources/
β β βββ images/
β β βββ kittens/
β β βββ a.jpg
β β βββ b.jpg
β β βββ c.jpg
β β βββ d.jpg
β βββ index.md
βββ _index.md
layouts/_default/single.html
{{ with .Resources.Match "**/*.jpg" }}
{{ range . }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
Slightly different example:
content/
βββ posts/
β βββ post-1/
β βββ page_resources/
β β βββ images/
β β β βββ kittens/
β β β β βββ d.jpg
β β β βββ c.jpg
β β βββ b.jpg
β βββ a.jpg
β βββ index.md
βββ _index.md
layouts/_default/single.html
{{ with .Resources.Match "**.jpg" }}
{{ range . }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
1 Like
regis
January 13, 2023, 5:42pm
4
I see then I guess it works in this context. Now Iβm trying with files whose basename I know, but not the extension. So the glob pattern should be **data.*
but it does not work (this is with resources.Match
)
assets/
βββ kittens/
β βββ data.json
β βββ data.yaml
βββ data.json
With the above, the **data.*
pattern only returns the kittens files.
I think this is a typo? site.Resources.Match
assets/
βββ global_resources/
β βββ data/
β β βββ kittens/
β β β βββ data.json
β β βββ data.json
β βββ images/
β β βββ kittens/
β β β βββ d.jpg
β β βββ c.jpg
β βββ b.jpg
β βββ data.json
βββ a.jpg
βββ data.json
layouts/_default/single.html
{{ with resources.Match "**data.*" }}
{{ range . }}
{{ .RelPermalink }}<br>
{{ end }}
{{ end }}
rendered
/data.json
/global_resources/data/data.json
/global_resources/data/kittens/data.json
/global_resources/data.json
1 Like
regis
January 13, 2023, 6:12pm
8
Thanks for testing this
Iβll keep looking into my project and try and figure out what I missed!