-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathindex-documentation.py
executable file
·55 lines (43 loc) · 1.64 KB
/
index-documentation.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# index for the documentation
import sys
from glob import glob
from collections import defaultdict
LANG = {"en": "english",
"hu": "hungarian"}
output = ["<!DOCTYPE html><body>"]
pages = {"html": defaultdict(list), "pdf": defaultdict(list)}
for path in glob("*/*"):
what, lang = path.split("/")
for path2 in glob(path + "/*"):
EXT = "/*.pdf" if what == "pdf" else "/index.html"
for fn in glob(path2 + EXT):
pages[what][lang].append(fn)
output.append("<h1>Documentation</h1>")
for what in pages:
output.append("<h2>%s</h2>" % what.upper())
output.append("<ul>")
for lang, entries in pages[what].items():
output.append("<li>%s</li>" % LANG.get(lang, lang))
output.append("<ul>")
for entry in entries:
output.append("<li><a href='{path}'>{fn}</a></li>".format(
path=entry, fn="/".join(entry.split("/")[-2:])))
output.append("</ul>")
output.append("</ul>")
output.append("</body>")
with open("index.html", "w") as index:
index.write("\n".join(output))
if len(sys.argv) > 1 and sys.argv[1] == "fix":
# fixes the static links in sphinx
# !!! ONLY RUN THIS ONCE !!!
import os
import subprocess as sp
os.chdir(os.path.expanduser("~/documentation/html/"))
ROOT = os.path.abspath(os.curdir)
for link in sp.Popen("find -type l -name _static".split(), stdout=sp.PIPE).stdout:
d = os.path.normpath(os.path.join(ROOT, link.rsplit("/", 1)[0]))
print(d)
os.chdir(d)
os.system(
r'find -type f -name "*.html" -exec sed -i "s/_static/..\/_static/" {} \;')