all repos — py-vite @ db6c8d55de470cea9632893762f52e118de2a831

the original vite, written in python

fix(make.py): handle jinja2 TemplateNotFound exception
icyphox icyph0x@protonmail.com
Thu, 22 Mar 2018 14:36:23 +0530
commit

db6c8d55de470cea9632893762f52e118de2a831

parent

b5a2b3335e12122a1e886bc14f02ba83483a8d2e

1 files changed, 17 insertions(+), 14 deletions(-)

jump to
M vite/make.pyvite/make.py

@@ -13,12 +13,12 @@ try:

sys.path.append(os.getcwd()) import config except ModuleNotFoundError: - print(bad('Error: config.py not found')) + print(bad('Error: config.py not found.')) # constants PAGES_PATH = 'pages/' BUILD_PATH = 'build/' -TEMPL_PATH = 'templates' +TEMPL_PATH = 'templates/' # jinja2

@@ -41,18 +41,21 @@

def main(): start = time.process_time() - template_file = TEMPL_PATH + '/index.html' - for page in os.listdir(PAGES_PATH): - html_text = markdown_render(page) - html_path = os.path.splitext(os.path.join(BUILD_PATH, page))[0] - if not os.path.exists(html_path): - os.mkdir(html_path) - output = jinja_render(html_text, template_file) - with open(os.path.join(html_path, 'index.html'), 'w') as f: - f.write(output) - print(run('Rendered %s' % (page))) - print(info('Done in %0.5fs' % (time.process_time() - start))) - + template_file = TEMPL_PATH + config.template + try: + for page in os.listdir(PAGES_PATH): + html_text = markdown_render(page) + html_file= os.path.splitext(os.path.join(BUILD_PATH, page))[0] + if not os.path.exists(html_file): + os.mkdir(html_file) + output = jinja_render(html_text, template_file) + with open(os.path.join(html_file, 'index.html'), 'w') as f: + f.write(output) + print(run('Rendered %s.' % (page))) + print(info('Done in %0.5fs.' % (time.process_time() - start))) + except jinja2.exceptions.TemplateNotFound: + print(bad('Error: specified template not found: %s' % (template_file))) + if __name__ == "__main__": main()