-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathREADME_to_get_sidebar.py
More file actions
46 lines (38 loc) · 1.29 KB
/
Copy pathREADME_to_get_sidebar.py
File metadata and controls
46 lines (38 loc) · 1.29 KB
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
import re
import datetime
def info(name):
print(datetime.datetime.now(), name, '写入完毕')
def re_findall(rule, doc):
return re.compile(rule, re.DOTALL).findall(doc)
# 1) 目录的预处理
with open('./README.md', 'rb') as fi:
doc = fi.read()
L_job1 = re_findall(
rb'<!-- menu_base -->(.*?)<!-- menu_base -->', doc)
L_job2 = re_findall(
rb'<!-- menu_write -->.*?<!-- menu_write -->', doc)
if L_job1 and L_job2:
menu = b'<!-- menu_write -->' + L_job1[0] + b'<!-- menu_write -->'
menu = b'\r\n'.join((x.strip() for x in menu.splitlines()))
with open('./README.md', 'wb') as fo:
fo.write(doc.replace(L_job2[0], menu))
# 2) sidebar和intro匹配
with open('./README.md', 'rb') as fi:
doc = fi.read() # .replace(b'/docs/', b'')
L_job1 = re_findall(
rb'<!-- menu -->.*?<!-- menu -->', doc)
L_job2 = re_findall(
rb'<!-- introduction -->.*?<!-- introduction -->', doc)
# with open('./docs/README.md', 'wb') as fo:
# info('./docs/README.md')
# fo.write(doc)
if L_job1:
sidebar = './_sidebar.md'
with open(sidebar, 'wb') as fo:
info(sidebar)
fo.write(L_job1[0])
if L_job2:
intro = './docs/00.Python/Introduction.md'
with open(intro, 'wb') as fo:
info(intro)
fo.write(L_job2[0])