-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.py
44 lines (35 loc) · 1.36 KB
/
compile.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
# -*- coding: utf-8 -*-
from glob import glob
from os import path, makedirs
from codecs import open
from shutil import copytree, rmtree
import markdown
from jinja2 import Template
MENU = [
{'file': 'index', 'icon': 'icon-info-sign', 'name': u'책 소개'},
{'file': 'peek', 'icon': 'icon-book', 'name': u'미리 보기'},
{'file': 'problems', 'icon': 'icon-question-sign', 'name': u'연습 문제'},
{'file': 'src', 'icon': 'icon-list-alt', 'name': u'소스 코드'},
{'file': 'errata', 'icon': 'icon-ok', 'name': u'정오표'},
{'file': 'buy', 'icon': 'icon-shopping-cart', 'name': u'구입하기'},
]
template = Template(open('template.html', encoding='utf-8').read())
# md = markdown.Markdown()
def compile_page(source, dest):
s = open(source, encoding='utf-8')
d = open(dest, 'w', encoding='utf-8')
compiled = markdown.markdown(s.read(), ['footnotes', 'tables'])
d.write(template.render(MENU=MENU, content=compiled))
print 'generated', dest
def main():
if not path.exists('output'):
makedirs('output')
else:
rmtree('output/static')
for source in glob('pages/*.md'):
page_name = '.'.join(path.basename(source).split('.')[:-1])
dest = path.join('output', page_name + '.html')
compile_page(source, dest)
copytree('static', 'output/static')
if __name__ == '__main__':
main()