HTDE HTDE - 5 months ago 40
Git Question

How to Enable Directory Indexing on GitHub Pages

I need to display directory contents on GH Pages.

Would prefer

  1. Automatically, without index.html

  2. A tool or library for automatically generating the index.html

  3. Any other method

So, if I have a FS in my GH Pages repository:[username]/[username]

- app/
- core/
- init.js
- lib/
- Element.animate.js
- Object.overlay.js
- mod/
- anim/
- global/
- carousel/
- carousel.js
- global.js
- ext/
- cfgs.js

I would want each directory URL to index as usual, like so.


- app/
- lib/
- mod/
- ext/


- carousel/
- global.js

The only thing I can think of is preference #2, write or find a script to automatically generate the index.html from the GitHub Repo page or the local Repo on my FS.


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 file for the directory.

""" Build index from directory listing </path/to/directory> [--header <header text>]

% for name in names:
    <li><a href="${name}">${name}<a></li>
% 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()
    args = parser.parse_args()
    fnames = [fname for fname in sorted(os.listdir(
              if fname not in EXCLUDED]
    header = (args.header if args.header else os.path.basename(
    print(Template(INDEX_TEMPLATE).render(names=fnames, header=header))

if __name__ == '__main__':