How to serve a directory listing of a static folder #2212
Unanswered
paul-dickman
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I'm not completely sure what you mean by "browsing the directory". If you want to list all the files in a directory relative to <!-- List refs to files in folder on path relative to ./static -->
{{ $path := .Get "path" }}
{{ $filepath := path.Join "/static" $path }}
{{ $files := readDir $filepath }}
{{ if (fileExists $filepath) }}
<ul class="list-unstyled">
{{ range $files }}
{{ $f := printf "%s/%s" $path .Name | relURL }}
<li><a href="{{ $f }}" download>{{ .Name }}</li>
{{ end }}
</ul>
{{ end }} Add this code to a shortcode, on path |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to migrate a course webpage to wowchemy-book. I'd like to add a download directory under static and set it up so that when anyone browses that directory they see a listing of all files in that directory. On my existing site the directory listing is accomplished using a PHP script, but that doesn't seem to work (I believe it's netlify that won't deploy PHP files).
I'm open to any other methods to achieve my goal, which is that any files are dump in a particular directory become available on the website. The directory contains around 500 files.
Beta Was this translation helpful? Give feedback.
All reactions