How to Enable Directory Indexing on GitHub Pages

前端 未结 4 1249
臣服心动
臣服心动 2021-02-04 05:55

I need to display directory contents on GH Pages.

Would prefer

  1. Automatically, without index.html
  2. A tool or library for automatically generating t
4条回答
  •  伪装坚强ぢ
    2021-02-04 06:08

    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()

提交回复
热议问题