Iterate over files in a directory

Hello,
I’m porting a website to zola and I was wondering if there is a way to iterate over the files of a directory in the source tree (e.g. in static).

The use case is to implement a statically generated image gallery: a directory will contain all the images of the gallery, with a loop I want to iterate over all the files of that directory, produce the thumbnails and link to the full resolution image.

Is it possible to do so? I couldn’t find a way.
Thanks!

Just as an information, the solution I’m using so far is to use load_data with a file generated automatically.

This works, but of course the problems are"

  • the necessity of an external script and building phase and
  • most importantly, the fact that information regarding the galleries is sparse (or the script is smart enough).

Having something like hugo does (readDir IIRC) would be nicer I think.

It’s not really possible right now. I’m going to work on Unify the usage of `path` parameter in functions · Issue #977 · getzola/zola · GitHub next and an equivalent to readDir could make sense to add.
Would you only use it to read dirs from static?

Well, not necessary only from static and actually for the same use case (gallery) being able to access co-located data would be great, too.

In hugo I used to have shortcodes for adding a gallery to a page, so it also makes sense, to me, to have a directory that contains the page for a topic and the gallery/galleries to be displayed in that page.

You can already do that in the content with colocated assets and a gallery example: Image processing | Zola

Oh wow! I didn’t know that :slight_smile: I could use that, I don’t have a compelling need to place images in static.

This being said, having a similar function to access static could be useful.

Thank you!