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?
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 }}
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
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!