-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy
executable file
·75 lines (56 loc) · 1.85 KB
/
deploy
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
#!/usr/bin/env python
from __future__ import print_function
from subprocess import check_call
import os
compressible = {'html': 'html', 'css': 'css', 'js': 'javascript'};
#compress: path -> nil
#side effect: file is minified and gzipped.
def compress(handle):
ext = os.path.splitext(handle)[1][1:]
if ext not in compressible:
print("Did not compress " + handle)
print("\text: " + os.path.splitext(handle)[1])
return
#For certain types, minification is possible.
if ext == 'css':
check_call(['yuicompressor', handle, '-o', handle])
check_call(['gzip', handle])
check_call(['mv', handle + '.gz', handle])
print("Successfully compressed " + handle)
#upload: path -> nil
#side effect: file is uploaded to s3.
def upload(handle):
cmd = ['s3cmd']
ext = os.path.splitext(handle)[1][1:]
if ext in compressible:
cmd += ['-m',
'text/'+compressible[ext],
"--add-header='Content-Encoding: gzip'"]
path_array = handle.split('/')[1:]
is_second_level = len(path_array) <= 2 and path_array[-1] == 'index.html'
if not is_second_level:
cmd += ["--add-header='Cache-Control: max-age=604800'"]
else:
cmd += ["--add-header='Cache-Control: max-age=86400'"]
cmd += ['put', handle, os.path.join('s3://www.bitlimn.com', handle[6:])]
print(' '.join(cmd))
check_call(' '.join(cmd), shell=True)
#walk_site: (path -> nil) -> nil
#side effect: runs fn() on all files in _site.
def walk_site(fn):
for (path, _, files) in os.walk('_site'):
for handle in files:
fn(os.path.join(path, handle))
def main():
#Remove previous site
check_call(['rm', '-rf', '_site'])
#Compile site
check_call(['compass', 'compile'])
check_call(['jekyll'])
#Compress the compressible files in the finished site.
walk_site(compress)
#Upload everything to s3. Set the compressed files' content-encoding
#to gzip and upload.
walk_site(upload)
if __name__ == '__main__':
main()