Automating inserting markdown of all images in a subfolder?

Hi guys, is there a way to automate inserting all images in a subfolder to a post? maybe using shortcode?

folder structure:

so lets say in a, instead of manually writing





we just write

{{< images in album1 >}}

and it automatically creates markdown for all the images in that folder.

is it possible?

Check out and It isn’t a shortcode, per se, but you can do things like drop all the images in a folder and have a gallery created.

short sample

I use ./gallery for the pictures and use this in my single template

{{range .Resources.Match "gallery/*" }}
		<img src="{{ .RelPermalink }}"  /> 
{{ end }}

@ju52 thanks for example, but doesn’t work as shortcode.

I ended up writing it myself. here is it as a shortcode.

add these to album.html in the shortcode folder:

<!-- put bunch of photos in /static/img/albumName -->
<!-- and insert shortcode {{< album albumName >}} in -->
{{ $albumUrl := print "/static/img/" ($.Get 0) }}
{{ range readDir $albumUrl }}
    {{ $imgURL := print "img/" ($.Get 0) "/" .Name | absURL }}
    <p><img src="{{ $imgURL }}"/></p>
{{ end }}

@Hakxslo756 the reason @ju52’s shortcode didn’t work for you is because your images are under static/.

The disadvantage of keeping your images under static/ is that you cannot do image processing on them, e.g. Resize, Fit, Fill. (Obviously not everyone needs those features, though).

Using your shortcode as an example, let’s say you wanted to resize all images to 400px width, then link to the original. You could do this:

{{ $page := .Site.GetPage "/img" }}
{{ $images := $page.Resources.ByType "image" }}

{{ range $images }}
  {{ $original := . }}
  {{ $resized := .Resize "400x" }}
    <a href="{{ $original.Permalink}}">
      <img src="{{ $resized.Permalink }}"/>
{{ end }}

This assumes your images could be under a page bundle at content/img, e.g.:

│   └───img
│           nasa-1.jpg
│           nasa-2.jpg
│           nasa-3.jpg

thanks. i understand the benefit of using resources as opposed to raw files now.
my original question was to insert all files in an arbitrary subfolder, which enables decoupling of post and its images.

so i can do hugo new blog/ and then insert the shortcode {{< album albumName >}} after writing introductory texts.

I think yours and @ju52’s solution is great, but for a different usecase.

How can I ignore a file (e.g. “.DS_Store”) when using this shortcode?