Skip or ignore files when using range readDir

Hi, I am using this shortcode to display all images from a folder in a post:

{{ $albumUrl := print "/content/" ($.Get 0) }}
{{ range readDir $albumUrl }}
    {{ $imgURL := print "img/" ($.Get 0) "/" .Name | absURL }}
    <p><img src="{{ $imgURL }}"/></p>
{{ end }}

It all works fine but I have a small problem. macOS creates a hidden “.DS_Store” file that gets displayed in the album as well. How can I skip/ignore this specific file?

You can try adding some conditional logic within the above range like so: {{ if ne .Name ".DS_Store" }}

However it would be best if you deleted these files from your project’s folder recursively using the terminal (a casual search will show you how). Also add these files to your .gitignore file.

The thing is that the file gets recreated every time I add something to the folder. I already have ignoreFiles = [".DS_Store"] in my config.toml and added it to my global .gitignore.

I tried to write a conditional but failed. It works but it will not skip/ignore the file.

{{ $albumUrl := print "/content/" ($.Get 0) }}
{{ range readDir $albumUrl }}
	{{ if ne .Name ".DS_Store" }}
		<div>invalid file found</div>
	{{ else }}
    	{{ $imgURL := print ($.Get 0) "/" .Name | absURL }}
    	<p><img src="{{ $imgURL }}"/></p>
    {{ end }}
{{ end }}

ignoreFiles is designed to ignore files to be processed by the template system. Your shortcode needs its own logic because it has super cosmic power (to view the filesystem). :sunglasses:

If you are having trouble ignoring that file you might just invert it and only process images by extensions.