forked from NCIP/gdc-docs
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuildencyclopedia.py
46 lines (37 loc) · 1.19 KB
/
buildencyclopedia.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
"""updates the encyclopedia section in the mkdocs.yml
should be run whenever a file is removed or added into the directory"""
import os
import yaml
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
ABSFILEPATH = os.path.dirname(os.path.realpath(__file__))
FILEARRAY = os.listdir(ABSFILEPATH + "/docs/Encyclopedia/pages")
FILEARRAY = sorted(FILEARRAY, key=str.lower)
with open(ABSFILEPATH + "/mkdocs.yml", "r") as f:
doc = yaml.load(f, Loader=Loader)
encycdict = next(
d for (index, d) in enumerate(doc["nav"]) if d.get("Encyclopedia", False) != False
)
newlist = []
for x in range(len(FILEARRAY)):
if FILEARRAY[x][-3:] == ".md":
tempdict = {
FILEARRAY[x][:-3].replace("_", " "): "".join(
["Encyclopedia/pages/", FILEARRAY[x][:-3], ".md"]
)
}
newlist.append(tempdict)
encycdict["Encyclopedia"] = newlist
with open(ABSFILEPATH + "/mkdocs.yml", "w+") as f:
f.write(
yaml.dump(
doc,
default_flow_style=False,
explicit_start=True,
indent=2,
width=80,
Dumper=Dumper,
)
)