all repos — py-vite @ 3366339167307aab074e6a82c11fd41521898335

the original vite, written in python

feat(make.py): now supports templating!
icyphox icyph0x@protonmail.com
Sat, 17 Mar 2018 13:43:40 +0530
commit

3366339167307aab074e6a82c11fd41521898335

parent

8f71e8e669389da6bf38260b63550096372c0f87

1 files changed, 9 insertions(+), 5 deletions(-)

jump to
M make.pymake.py

@@ -6,14 +6,14 @@

# constants PAGES_PATH = 'pages/' BUILD_PATH = 'build/' -TEMPL_PATH = 'templates/' +TEMPL_PATH = 'templates' # jinja2 def jinja_render(html_text, template_file): - template_loader = jinja2.FileSystemLoader(searchpath=TEMPL_PATH) + template_loader = jinja2.FileSystemLoader('./') env = jinja2.Environment(loader=template_loader) template = env.get_template(template_file) - output = template.render(body=html_text) + output = template.render(title='test', body=html_text) return output def markdown_render(filename):

@@ -21,10 +21,14 @@ html_text = markdown_path(PAGES_PATH + filename)

return html_text def main(): - template_file = TEMPL_PATH + 'template.html' + template_file = TEMPL_PATH + '/template.html' for page in os.listdir(PAGES_PATH): html_text = markdown_render(page) + html_file = os.path.splitext(page)[0] + '.html' output = jinja_render(html_text, template_file) - with open(BUILD_PATH + html_text, 'w') as f: + with open(BUILD_PATH + html_file, 'w') as f: f.write(output) print('Rendered %s' % (page)) + +if __name__ == "__main__": + main()