I’m trying to create a template or shortcode that lists the files in a directory.
My particular use-case is that I’d like to have a page that lists the contents of a directory full of .wav and .mp3 files. Each file does not require its own page, so having the list template/shortcode display a direct link to the file is what I’m trying to do.
Ideally, I’d like to figure this out on my own, as I’m mainly using Hugo as a hobby. If .ResourceType / .MediaType is indeed the correct direction to go in, please let me know. If not, all I ask is a point in the right direction, and I can eventually figure it out from there. Thank you!
So I tried your shortcode and couldn’t get it to function properly. After replacing your target directory with mine (static/audio), the page properly renders but does not list the files. Ju52, if you would be so kind, can you explain the string “/etc/%s/%s” found on line 10? I’m having a hard time understanding how to parse in my directory at that point. Would it be “/static/%s/%s” as to reflect my target directory?
My apologies for the lack of understanding, I’m in no way a programmer, ha.
$path ist the parameter from the shortcode
.Name comes from the RANGE operation, range goes over files, .Name ist simply the filename
Print puts all together
The call should be
{{< shortlist path=“apache2/sites-enabled” type=“conf”>}}
You should put your files under /assets or /static. Hugo will copy all from static and all referenced files from assets.
PS:
I linked /assets/etc to /etc - to document my linux configuration
you could use [resources.GetMatch](https://gohugo.io/content-management/page-resources/#methods), if the files are in the same directory [/ subdirectory]