-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate.py
66 lines (48 loc) · 1.78 KB
/
generate.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
import pathlib
from jinja2 import Environment, PackageLoader
import models
import os
import shutil
env = Environment(loader=PackageLoader('models', 'templates'))
STATIC_DIR = './static/'
OUTPUT_DIR = './_output/'
static_dir_path = pathlib.Path(STATIC_DIR)
output_dir_path = pathlib.Path(OUTPUT_DIR)
shutil.copytree(static_dir_path, output_dir_path)
template = env.get_template('blog-entry.html')
resume = env.get_template('resume.html')
portfolio = env.get_template('portfolio.html')
about = env.get_template('about.html')
labs = env.get_template('labs.html')
with open(os.path.join(OUTPUT_DIR, 'resume.html'), 'w') as html:
html.write(resume.render())
with open(os.path.join(OUTPUT_DIR, 'portfolio.html'), 'w') as html:
html.write(portfolio.render())
with open(os.path.join(OUTPUT_DIR, 'about.html'), 'w') as html:
html.write(about.render())
with open(os.path.join(OUTPUT_DIR, 'lab.html'), 'w') as html:
html.write(labs.render())
articles = []
for n in models.posts:
condition = False
articles.append({
'title' : n["data"].title,
'url' : n["data"].url,
'current' : condition
})
for post in models.posts:
g = post["data"].spit_dict()
a = list(articles)
for x in a:
i = a.index(x)
if x["url"] == g["url"]:
a[i]["current"] = True
else:
a[i]["current"] = False
g["posts"] = a
with open(os.path.join(OUTPUT_DIR, g["url"]), 'w') as html:
html.write(template.render(g))
if models.posts[len(models.posts)-1] == post:
with open(os.path.join(OUTPUT_DIR, 'index.html'), 'w') as html:
html.write(template.render(g))