List files in a directory

a littel sample :wink:
I use this to make a linux doc (with sym link /etc to assets/etc)

shortlist.html shortcode

{{ $path     := .Get "path" }}
{{ $filepath := printf "assets/etc/%s" $path }}
{{ $files    := readDir $filepath }}
{{ $ext := default "-" (.Get "type" )}}
{{ if (fileExists $filepath)}}
<div class="pa2 mh4 ba">
{{- range $files }}
	{{ if (and (ne (substr .Name 0 1) "_") (not .IsDir)) }}{{ $f := resources.Get (printf "/etc/%s/%s" $path .Name)}}
		{{ $e := findRE "\\w+$" .Name }}
		{{ if (or ( eq $ext "-") (in $e $ext) )}}
			<a class="w-auto pr2" href={{$f.Permalink }} type=text/plain download>{{ .Name }}</a>
		{{end}}
	{{end}}
{{- end }}
</div>
{{end}}

how I call it

{{< lshortlist path="apache2/sites-enabled" type="conf">}}

2 Likes