forked from hkalexling/mango-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiki.py
31 lines (22 loc) · 861 Bytes
/
wiki.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
import os
import shutil
dir_content = os.listdir('./docs/Wiki')
files = [f for f in dir_content if \
os.path.isfile(os.path.join('./docs/Wiki', f)) and \
f.endswith('.md') and \
not f == 'README.md' ]
files.sort()
titles = [' '.join(os.path.splitext(f)[0].split('-')) for f in files]
path = ['/Wiki/{}'.format(os.path.splitext(f)[0]) for f in files]
new_lines = ['\t- [{}]({})\n'.format(t, path[i]) for (i, t) in enumerate(titles)]
shutil.copy2('./docs/sidebar.md', './docs/_sidebar.md')
lines = []
with open('./docs/sidebar.md', 'r') as f:
lines = f.readlines()
matches = [idx for (idx, val) in enumerate(lines) if '- Wiki' in val]
if len(matches) == 0:
raise ValueError('No line contains `- Wiki`')
idx = matches[0] + 1
lines[idx:idx] = new_lines
with open('./docs/_sidebar.md', 'w') as f:
f.write(''.join(lines))