-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.py
executable file
·123 lines (84 loc) · 3.49 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#! /usr/bin/env python3
import os
import jinja2
import markdown
import pathlib
from datetime import datetime
from dataclasses import dataclass
__here__ = pathlib.Path(__file__).resolve().parent
date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
extension_configs = {"toc": {"permalink": " ¶"}}
md = markdown.Markdown(
extensions=["meta", "toc", "extra"], extension_configs=extension_configs
)
env = jinja2.Environment(loader=jinja2.FileSystemLoader(str(__here__ / "templates")))
# grab yeps --------------------------------------------------------------------------------------
tags = ["meta", "standard", "trait"]
@dataclass
class YEP:
index: int
title: str
authors: [str]
status: str
tags: [str]
post_history: [str]
content: str
@property
def metadata(self) -> str:
out = "<table>\n"
out += f"<tr><th>YEP:</th><td>{self.index}</td></tr>\n"
out += f"<tr><th>Title:</th><td>{self.title}</td></tr>\n"
out += f"<tr><th>Authors:</th><td>{', '.join(self.authors)}</td></tr>\n"
out += f"<tr><th>Status:</th><td>{self.status}</td></tr>\n"
out += f"<tr><th>Tags:</th><td>{', '.join(self.tags)}</td></tr>\n"
out += f"<tr><th>Post-History:</th><td>{', '.join(self.post_history)}</td></tr>\n"
out += "</table>\n"
return out
yeps = []
for yep in os.listdir(__here__ / "yeps"):
with open(__here__ / "yeps" / yep, "r") as f:
s = f.read()
content = md.convert(s)
kwargs = dict()
kwargs["index"] = int(md.Meta["yep"][0])
kwargs["title"] = md.Meta["title"][0]
kwargs["authors"] = md.Meta["author"]
kwargs["status"] = md.Meta["status"][0]
kwargs["tags"] = md.Meta["tags"]
kwargs["post_history"] = md.Meta["post-history"]
kwargs["content"] = content
for t in kwargs["tags"]:
assert t in tags
yeps.append(YEP(**kwargs))
yeps.sort(key=lambda y: y.index)
# index -------------------------------------------------------------------------------------------
if not os.path.isdir(__here__ / "public"):
os.mkdir(__here__ / "public")
template = env.get_template("index.html")
with open(__here__ / "public" / "index.html", "w") as f:
f.write(template.render(yeps=yeps, title="yaq enhancement proposals", date=date))
# YEP-0 -------------------------------------------------------------------------------------------
if not os.path.isdir(__here__ / "public" / "000"):
os.mkdir(__here__ / "public" / "000")
template = env.get_template("yep0.html")
with open(__here__ / "public" / "000" / "index.html", "w") as f:
f.write(
template.render(
yeps=yeps,
title="yaq enhancement proposals",
date=date,
tags=tags,
)
)
# posts -------------------------------------------------------------------------------------------
template = env.get_template("yep.html")
for yep in yeps:
if not os.path.isdir(__here__ / "public" / str(yep.index).zfill(3)):
os.mkdir(__here__ / "public" / str(yep.index).zfill(3))
with open(__here__ / "public" / str(yep.index).zfill(3) / "index.html", "w") as f:
f.write(template.render(yep=yep, title=yep.title, date=date))
# css ---------------------------------------------------------------------------------------------
template = env.get_template("style.css")
for d, _, _ in os.walk(__here__ / "public", topdown=False):
with open(os.path.join(d, "style.css"), "w") as f:
f.write(template.render())