-
Notifications
You must be signed in to change notification settings - Fork 64
/
indexer.py
41 lines (39 loc) · 1.02 KB
/
indexer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
import os
import re
style = """
body{
font-family:sans-serif;
margin:20px;
}
table, th, td {
border: 1px solid black;
}
div{
border: 1px solid black;
padding:5px;
}
"""
print("indexing...")
for r,ds,fs in os.walk("./"):
if "." in r[1:]:
continue
if "index.html" in fs:
continue
print(r)
html = "<html><style>"+style+"</style><h1>"+r+"</h1><table><tr><td>🔙</td><td><a href=\"../\">../</a></td></tr>"
for d in ds:
html += "<tr><td>📁</td><td><a href=\""+d+"\">"+d+"/</a></td></tr>"
for f in fs:
if f[0] == ".":
continue
html += "<tr><td>📄</td><td><a href=\""+f+"\">"+f+"</a></td></tr>"
html+="</table>"
if "README.md" in fs:
t = re.sub(r'\[([^\[\n]*?)\]\((.*?)\)',r'<a href="\2">\1</a>',
re.sub(r'!\[[^\[\n]*?\]\((.*?)\)',r'<img src="\1" width="300"></img>',
open(r+"/"+"README.md",'r').read().replace("\n","<br>")))
html+='<h2>📖 README.md</h2><div style="font-family:monospace">'+t+"</div>";
html += "</html>"
open(r+"/index.html",'w').write(html);
print("done.")