How to Enable Directory Indexing on GitHub Pages

前端 未结 4 1258
臣服心动
臣服心动 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:09

    Better is this way which will go into subdirectory and make index files for them as well

    """ Build index from directory listing
    
    make_index.py  [--header 
    ] """ from __future__ import print_function import os.path, time INDEX_TEMPLATE = r""" ${header}

    Index of ${header}

    % for name in dirnames: % endfor % for name in filenames: % endfor

    [ICO] Name Last modified Size Description

    [PARENTDIR] Parent Directory   -  

    [DIR] ${name} ${time} -  
    [DIR] ${name} ${time} -  
    """ EXCLUDED = ['index.html'] import os import argparse # May need to do "pip install mako" from mako.template import Template def fun(dir,rootdir): print('Processing: '+dir) filenames = [fname for fname in sorted(os.listdir(dir)) if fname not in EXCLUDED and os.path.isfile(dir+fname)] dirnames = [fname for fname in sorted(os.listdir(dir)) if fname not in EXCLUDED ] dirnames = [fname for fname in dirnames if fname not in filenames] # header = os.path.basename(dir) f = open(dir+'/index.html','w') print(Template(INDEX_TEMPLATE).render(dirnames=dirnames,filenames=filenames, header=dir,ROOTDIR=rootdir,time=time.ctime(os.path.getctime(dir))),file=f) f.close() for subdir in dirnames: try: fun(dir+subdir+"/",rootdir+'../') except: pass def main(): parser = argparse.ArgumentParser() parser.add_argument("directory") parser.add_argument("--header") args = parser.parse_args() fun(args.directory+'/','../') if __name__ == '__main__': main()

提交回复
热议问题