forked from brainhackorg/brainhack-local-template_2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.py
36 lines (29 loc) · 885 Bytes
/
generator.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
__author__ = "akeshavan"
from jinja2 import Environment, FileSystemLoader
import os
import simplejson as json
def load_json(filename):
"""Load data from a json file
Parameters
----------
filename : str
Filename to load data from.
Returns
-------
data : dict
"""
with open(filename, "r") as fp:
data = json.load(fp)
return data
files_to_generate = [
{"filename": "index.html.j2", "location": "./_site"},
{"filename": "css/stylish-portfolio.css.j2", "location": "./_site"},
]
env = Environment(loader=FileSystemLoader("./_site"))
info = load_json("data.json")
for f in files_to_generate:
template = env.get_template(f["filename"])
outfile = os.path.join(f["location"], f["filename"].replace(".j2", ""))
print("writing", outfile)
with open(outfile, "w") as q:
q.write(template.render(**info))