-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.py
93 lines (71 loc) · 2.54 KB
/
build.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import shutil
import sys
import jinja2
import markdown
from jinja2 import FileSystemLoader
from datetime import datetime
from util import *
def build():
os.chdir(os.path.dirname(os.path.abspath(__file__)))
shutil.rmtree("generated_templates", ignore_errors=True)
os.mkdir("generated_templates")
print("Loading the urls...")
urls = load_data("urls")
print("Loading other data...")
data = {
"urls": urls,
"about": load_data("about"),
"news": by_date_desc(titled(load_data("news"))),
"examples": titled(load_data("examples")),
"languages": load_data("languages"),
"year": datetime.now().year,
}
print("Rendering bibliography...")
fetch_bibliography_into(data)
print("Fetching example data from git repository...")
fetch_examples_into(data, "v1.4.0")
print("Rendering wiki...")
fetch_wiki("dev")
print("Computing routes and template data...")
pages = {
urls["index"]: ("index.html", {}),
urls["about"]: ("about.html", {}),
urls["publications"]: ("publications.html", {}),
urls["news"]: ("news.html", {}),
urls["examples"]: ("showcases.html", {}),
urls["try_online"]: ("try_online.html", {}),
urls["wiki"]: ("wiki.html", {}),
urls["alpinist"]: ("alpinist.html", {}),
urls["vesuv"]: ("vesuv.html", {}),
urls["veymont"]: ("veymont.html", {}),
}
pages.update({
urls["article"] % slugify(article["title"]): ("article.html", article)
for article in data["news"]
})
pages.update({
urls["example"] % slugify(example["title"]): ("example.html", example)
for example in data["examples"]
})
shutil.rmtree("build", ignore_errors=True)
os.mkdir("build")
env = jinja2.Environment(loader=FileSystemLoader(["templates", "generated_templates"]), autoescape=True)
env.filters["md"] = markdown.markdown
env.filters["slugify"] = slugify
for path, (template, extra_data) in pages.items():
print("Rendering {}...".format(path))
assert path[0] == "/"
path = path[1:]
*dir, file = path.split("/")
file = file or "index.html"
dir = "/".join(["build"] + dir)
path = dir + "/" + file
os.makedirs(dir, exist_ok=True)
data = data.copy()
data.update(extra_data)
with open(path, "w") as f:
env.get_template(template).stream(data).dump(f)
shutil.copytree("static", "build", dirs_exist_ok=True)
if __name__ == "__main__":
build()