forked from codeforamerica/git-jekyll-preview
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjekyll.py
40 lines (29 loc) · 1.15 KB
/
jekyll.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
from os.path import join, exists
from logging import getLogger
from shutil import copyfile
from util import run_cmd, touch, is_fresh, locked_file
jlogger = getLogger('jekit')
def jekyll_build(checkout_path):
'''
'''
checkout_lock = checkout_path + '.jekyll-lock'
jekyll_path = join(checkout_path, '_site')
built_hash_file = checkout_path + '.built-hash'
hash_file = checkout_path + '.commit-hash'
if exists(jekyll_path) and is_fresh(jekyll_path):
return jekyll_path
with locked_file(checkout_lock):
do_build = True
if exists(built_hash_file):
built_hash = open(built_hash_file).read().strip()
commit_hash = open(hash_file).read().strip()
if built_hash == commit_hash:
jlogger.debug('Skipping build to ' + jekyll_path)
do_build = False
if do_build:
jlogger.info('Building jekyll ' + jekyll_path)
run_cmd(('jekyll', 'build'), checkout_path)
if exists(hash_file):
copyfile(hash_file, built_hash_file)
touch(jekyll_path)
return jekyll_path