-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.py
More file actions
78 lines (64 loc) · 1.43 KB
/
generate.py
File metadata and controls
78 lines (64 loc) · 1.43 KB
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
import yaml
import os
import glob
from jinja2 import Environment, FileSystemLoader
letters = [
'א',
'ב',
'ג',
'ד',
'ה',
'ו',
'ז',
'ח',
'ט',
'י',
'כ',
'ך',
'ל',
'מ',
'ם',
'נ',
'ן',
'ס',
'ע',
'פ',
'ף',
'צ',
'ץ',
'ק',
'ר',
'ש',
'ת',
'בﬞ',
'גﬞ',
'דﬞ',
'זﬞ',
'טﬞ',
'כﬞ',
'פﬞ',
'שﬞ',
]
html_path = "_site"
def main():
buttons = ""
for letter in letters:
buttons += f"""<button class="button letter rashi">{letter}</button>"""
render(template="editor.html", filename="index.html", buttons=buttons)
for filename in glob.glob("words-*.yaml"):
name = filename[0:-5]
with open(filename) as fh:
words = yaml.safe_load(fh)
render(template="words.html", filename=f"{name}.html", words=words)
def render(template, filename=None, **args):
root = os.path.dirname(os.path.abspath(__file__))
templates_dir = os.path.join(root, "templates")
env = Environment(loader=FileSystemLoader(templates_dir), autoescape=True)
html_template = env.get_template(template)
html = html_template.render(**args)
full_path = os.path.join(html_path, filename)
dir_path = os.path.dirname(full_path)
os.makedirs(dir_path, exist_ok=True)
with open(full_path, "w") as fh:
fh.write(html)
main()