-
Notifications
You must be signed in to change notification settings - Fork 109
/
make.py
77 lines (58 loc) · 2.07 KB
/
make.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import glob
import os
import subprocess
import sys
import PIL.Image
def call(command):
print('$', command)
r = subprocess.call(command, shell=True)
if r != 0:
sys.exit(r)
def make():
call('mkdocs build')
call('echo -n "9530b96b26004efa430cc08502bdb442" > site/baidu_verify_codeva-bkxO1ABXUL.html')
call('echo -n "03890937a90586962ffe04ea5adaa43c" > site/03890937a90586962ffe04ea5adaa43c.txt') # 360
call('echo -n "google-site-verification: google9b75b4b4147e247b.html" > site/google9b75b4b4147e247b.html')
call('echo -n "google.com, pub-5236818090688638, DIRECT, f08c47fec0942fa0" > site/ads.txt')
def mini():
for html in glob.glob('site/**/*.html', recursive=1):
with open(html, 'r+') as f:
data = f.read()
f.seek(0)
f.truncate(0)
f.write(data)
def exam_imgs_unused():
imgs = glob.glob('docs/img/**/*.*', recursive=1)
docs = glob.glob('docs/content/**/*.md', recursive=1)
docs.append('docs/index.md')
imgs_dict = dict.fromkeys(imgs, 0)
for e in docs:
with open(e) as f:
for line in f:
line = line.strip()
if line.startswith('![img]'):
p = line[7:-1]
p = os.path.normpath(os.path.join(os.path.dirname(e), p))
assert p in imgs_dict, f'missed {e} {p}'
imgs_dict[p] += 1
for k, v in imgs_dict.items():
assert v != 0, f'unused {k}'
def exam_imgs_format():
imgs = glob.glob('docs/img/**/*.*', recursive=1)
for e in imgs:
i = PIL.Image.open(e)
assert i.format in ['JPEG', 'GIF'], f'format {e} {i.format}'
def exam_imgs_size():
imgs = glob.glob('docs/img/**/*.*', recursive=1)
for e in imgs:
i = PIL.Image.open(e)
assert i.size[0] == 480 and i.size[1] % 2 == 0, f'imsize {e} {i.size[0]}x{i.size[1]}'
def main():
os.chdir(os.path.dirname(os.path.abspath(__file__)))
exam_imgs_unused()
exam_imgs_format()
exam_imgs_size()
make()
mini()
if __name__ == '__main__':
main()