forked from mohanson/accu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.py
74 lines (57 loc) · 2.12 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
import glob
import os
import subprocess
import sys
import htmlmin
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()
data = htmlmin.minify(data, remove_comments=True,
remove_empty_space=True,
remove_all_empty_space=True,
reduce_empty_attributes=True,
reduce_boolean_attributes=True)
f.seek(0)
f.truncate(0)
f.write(data)
def exam_imgs_unused():
imgs = [i[4:] for i in 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]
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_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_size()
make()
mini()
if __name__ == '__main__':
main()