refactor(make.py): modularize code
icyphox icyph0x@protonmail.com
Sat, 17 Mar 2018 02:13:50 +0530
1 files changed,
9 insertions(+),
7 deletions(-)
jump to
M
make.py
→
make.py
@@ -1,15 +1,17 @@
from markdown2 import markdown_path from glob import glob import os +import jinja2 # constants PAGES_PATH = 'pages/' BUILD_PATH = 'build/' +TEMPL_PATH = 'templates/' -for filename in os.listdir(PAGES_PATH): - html = markdown_path(PAGES_PATH + filename) - html_file = os.path.splitext(filename)[0] + '.html' - with open(BUILD_PATH + html_file, 'w') as f: - f.write(html) - print('Rendered %s' % (html_file)) - +# jinja2 +def jinja_render(markdown_text, template_file): + template_loader = jinja2.FileSystemLoader(searchpath=TEMPL_PATH) + env = jinja2.Environment(loader=template_loader) + template = env.get_template(template_file) + output = template.render(body=markdown_text) + return output