/
app.py
64 lines (43 loc) · 1.34 KB
/
app.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
import os
from livereload import Server
BUILD_DIR = 'build'
DOCTYPE = (
'''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '''
'''"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'''
)
TEMPLATE_START = '''<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>TITLE</title>
<style type="text/css">
{{css}}
</style>
</head>
'''
with open('_layouts/container.html', 'rb') as f:
TEMPLATE_BODY = f.read()
TEMPLATE = DOCTYPE + TEMPLATE_START + TEMPLATE_BODY + '</html>'
def get_shared_css():
names = ['basic']
css = []
for name in names:
with open(os.path.join('_styles', name + '.css'), 'rb') as f:
css.append(f.read())
return '\n'.join(css)
def build(name, inline=False):
with open(os.path.join(name, 'content.html')) as f:
content = f.read()
with open(os.path.join(name, 'style.css')) as f:
style = f.read()
rv = TEMPLATE.replace('{{css}}', '\n'.join([get_shared_css(), style]))
rv = rv.replace('{{content}}', content)
with open(os.path.join('_build', name + '.html'), 'wb') as f:
f.write(rv)
def watch(name):
build(name)
def _build():
build(name)
server = Server()
server.watch(name, _build)
server.serve(root='_build')
watch('shipping')