all repos — py-vite @ 086bd7388515ac6ad12de7432be2d50f1f8d4bd6

the original vite, written in python

make.py (view raw)

 1from markdown2 import markdown_path
 2from glob import glob
 3import os
 4import jinja2
 5
 6# constants
 7PAGES_PATH = 'pages/'
 8BUILD_PATH = 'build/'
 9TEMPL_PATH = 'templates'
10
11# jinja2
12def jinja_render(html_text, template_file):
13    template_loader = jinja2.FileSystemLoader('./')
14    env = jinja2.Environment(loader=template_loader)
15    template = env.get_template(template_file)
16    output = template.render(title='test', body=html_text)
17    return output
18
19def markdown_render(filename):
20    html_text = markdown_path(PAGES_PATH + filename)
21    return html_text
22
23def main():
24    template_file = TEMPL_PATH + '/template.html'
25    for page in os.listdir(PAGES_PATH):
26        html_text = markdown_render(page)
27        html_file = os.path.splitext(page)[0] + '.html'
28        output = jinja_render(html_text, template_file)
29        with open(BUILD_PATH + html_file, 'w') as f:
30            f.write(output)
31            print('Rendered %s' % (page))
32
33if __name__ == "__main__":
34    main()