I need to display directory contents on GH Pages.
Would prefer
I also wanted to do this. I tried uploading an .htaccess
file with contents Options +Indexes
to the relevant directory, but that did not work.
So, I used your option #2, writing a tiny Python script to generate an index file for the directory.
""" Build index from directory listing
make_index.py [--header ]
"""
INDEX_TEMPLATE = r"""
${header}
% for name in names:
- ${name}
% endfor
"""
EXCLUDED = ['index.html']
import os
import argparse
# May need to do "pip install mako"
from mako.template import Template
def main():
parser = argparse.ArgumentParser()
parser.add_argument("directory")
parser.add_argument("--header")
args = parser.parse_args()
fnames = [fname for fname in sorted(os.listdir(args.directory))
if fname not in EXCLUDED]
header = (args.header if args.header else os.path.basename(args.directory))
print(Template(INDEX_TEMPLATE).render(names=fnames, header=header))
if __name__ == '__main__':
main()