Glob pattern to find files at the root and down the tree

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

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

Typo yes :slight_smile:

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

Thanks for testing this :pray:

I’ll keep looking into my project and try and figure out what I missed!