如何在GitHub页面上启用目录索引 [英] How to Enable Directory Indexing on GitHub Pages
问题描述
我需要在GH页面上显示目录内容。
宁愿
- 自动,无index.html
- 自动生成index.html的工具或库
- 任何其他方法
$ b $因此,如果我在我的GH Pages存储库中有一个FS:
http://github.com/ [用户名] / [用户名] .github.io /
:
script /
- app /
- core /
- init.js
- lib /
- Element.animate.js
- Object.overlay.js
- mod /
- anim /
- global /
- carousel /
- carousel.js
- global.js
- ext /
- cfgs.js
index.html
我希望每个目录URL都像往常一样索引,就像这样。
http:// [username] .github.io / script /
:
- app /
- lib /
- mod /
- ext /
http:// [username] .github.io / script / mod / anim / global /
- 转盘/
- global.js
我唯一能想到的是首选项#2,编写或查找脚本以从GitHub Repo页面自动生成index.html或我的FS上的本地回购。
我也想这样做。我尝试将 .htaccess
文件的内容选项+索引
上载到相关目录,但这不起作用。 / p>
因此,我使用了选项#2,编写了一个小小的Python脚本来为该目录生成一个索引文件。
从目录列表生成索引
$ b make_index.py< / path / to / directory> [ - header< header text>]
INDEX_TEMPLATE = r
< html>
< body>
< h2> $ {header}< / h2>
< p>
%名称中的名称:
< li>< a href =$ {name}> $ {name}< / a>< / li>
%endfor
< / p>
< / body>
< / html>
EXCLUDED = ['index.html']
导入os
导入argparse
#可能需要做的事从mako.template导入模板
$ b def main():
parser = argparse.ArgumentParser()$bip install mako
b $ b 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()
I need to display directory contents on GH Pages.
Would prefer
- Automatically, without index.html
- A tool or library for automatically generating the index.html
- Any other method
So, if I have a FS in my GH Pages repository:
http://github.com/[username]/[username].github.io/
:
script/
- app/
- core/
- init.js
- lib/
- Element.animate.js
- Object.overlay.js
- mod/
- anim/
- global/
- carousel/
- carousel.js
- global.js
- ext/
- cfgs.js
index.html
I would want each directory URL to index as usual, like so.
http://[username].github.io/script/
:
- app/
- lib/
- mod/
- ext/
http://[username].github.io/script/mod/anim/global/
:
- 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
make_index.py </path/to/directory> [--header <header text>]
"""
INDEX_TEMPLATE = r"""
<html>
<body>
<h2>${header}</h2>
<p>
% for name in names:
<li><a href="${name}">${name}</a></li>
% endfor
</p>
</body>
</html>
"""
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()
这篇关于如何在GitHub页面上启用目录索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!