-
Notifications
You must be signed in to change notification settings - Fork 36
/
docmerge.py
47 lines (41 loc) · 1.51 KB
/
docmerge.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
# -*- coding: UTF-8 -*-
import os
import json
BASE_URL = '/static/h5/#/'
# since my python is default python2
# python3 -u "/Users/wakary/GitHub/uni/myp-ui/docmerge.py"
# merge docsAuto with docsExtra for header.json in docs
def doc_merge():
with open('./docs/header.json', 'r') as fp:
files = json.load(fp)
for f in files:
# header
header = files[f]
print(header)
content = '---\n'
content += 'title: '+header['title']+'\n'
content += 'type: '+header['type']+'\n'
content += 'order: '+str(header['order'])+'\n'
if 'page' in header:
content += 'page: '+BASE_URL+header['page']+'\n'
content += '---\n'
# auto content
auto_file = './docsAuto/mypUI/'+f+'/'+f+'.md'
is_file = os.path.isfile(auto_file)
if is_file:
with open(auto_file, 'r') as r:
lines = r.readlines()
for line in lines:
if not line.startswith('# '+f):
content += line
# extra content
extra_file = './docsExtra/'+f+'.md'
is_file = os.path.isfile(extra_file)
if is_file:
with open(extra_file, 'r') as e:
a = e.read()
content += a
with open('./docs/'+f+'.md', 'w', encoding='utf8') as w:
w.write(content)
if __name__ == '__main__':
doc_merge()