Files: a04710913fd81231203bcb6deb4cf848a871b55d / generator / generate.py
3840 bytesRaw
1 | import os |
2 | import shutil |
3 | |
4 | import common |
5 | import templates.index |
6 | import templates.entries |
7 | import templates.series |
8 | import templates.tag |
9 | import templates.year |
10 | import templates.month |
11 | import templates.day |
12 | import templates.entry |
13 | import templates.error |
14 | |
15 | |
16 | output_dir = "output" |
17 | |
18 | shutil.rmtree(output_dir, ignore_errors=True) |
19 | shutil.copytree("static", output_dir, dirs_exist_ok=True) |
20 | |
21 | os.makedirs(output_dir, exist_ok=True) |
22 | |
23 | for font in ["iosevka-grey", "iosevka-grey-mono"]: |
24 | os.makedirs(os.path.join(output_dir, f"style/fonts/{font}"), exist_ok=True) |
25 | shutil.copytree( |
26 | os.path.expanduser(f"~/Software/src/iosevka/dist/{font}/woff2"), |
27 | os.path.join(output_dir, f"style/fonts/{font}/woff2"), |
28 | dirs_exist_ok=True, |
29 | ) |
30 | shutil.copy( |
31 | os.path.expanduser(f"~/Software/src/iosevka/dist/{font}/{font}.css"), |
32 | os.path.join(output_dir, f"style/fonts/{font}"), |
33 | ) |
34 | shutil.copy( |
35 | os.path.expanduser("~/Software/src/iosevka/LICENSE.md"), |
36 | os.path.join(output_dir, f"style/fonts/{font}"), |
37 | ) |
38 | |
39 | os.makedirs(os.path.join(output_dir, "style/fonts/smol-emoji"), exist_ok=True) |
40 | shutil.copy( |
41 | os.path.expanduser(f"~/Software/src/smol-emoji/SmolEmoji-Regular.otf"), |
42 | os.path.join(output_dir, "style/fonts/smol-emoji"), |
43 | ) |
44 | shutil.copy( |
45 | os.path.expanduser(f"~/Software/src/smol-emoji/LICENSE"), |
46 | os.path.join(output_dir, "style/fonts/smol-emoji"), |
47 | ) |
48 | |
49 | with open(output_dir + "/index.html", "w") as file: |
50 | file.write(templates.index.html(common.entries)) |
51 | |
52 | os.makedirs(output_dir + "/entries", exist_ok=True) |
53 | with open(output_dir + "/entries/index.html", "w") as file: |
54 | file.write(templates.entries.html(common.entries)) |
55 | with open(output_dir + "/feed", "w") as file: |
56 | file.write(templates.entries.atom(common.entries)) |
57 | |
58 | for series in common.series: |
59 | os.makedirs(output_dir + common.url_of_series(series), exist_ok=True) |
60 | with open(output_dir + common.url_of_series(series) + "/index.html", "w") as file: |
61 | file.write(templates.series.html(common.entries, series)) |
62 | with open(output_dir + common.url_of_series_feed(series), "w") as file: |
63 | file.write(templates.series.atom(common.entries, series)) |
64 | |
65 | for tag in common.tags: |
66 | os.makedirs(output_dir + common.url_of_tag(tag), exist_ok=True) |
67 | with open(output_dir + common.url_of_tag(tag) + "/index.html", "w") as file: |
68 | file.write(templates.tag.html(common.entries, tag)) |
69 | with open(output_dir + common.url_of_tag_feed(tag), "w") as file: |
70 | file.write(templates.tag.atom(common.entries, tag)) |
71 | |
72 | for date in common.years: |
73 | os.makedirs(output_dir + common.url_of_year(date), exist_ok=True) |
74 | with open(output_dir + common.url_of_year(date) + "/index.html", "w") as file: |
75 | file.write(templates.year.html(common.entries, date)) |
76 | |
77 | for date in common.months: |
78 | os.makedirs(output_dir + common.url_of_month(date), exist_ok=True) |
79 | with open(output_dir + common.url_of_month(date) + "/index.html", "w") as file: |
80 | file.write(templates.month.html(common.entries, date)) |
81 | |
82 | for date in common.days: |
83 | os.makedirs(output_dir + common.url_of_day(date), exist_ok=True) |
84 | with open(output_dir + common.url_of_day(date) + "/index.html", "w") as file: |
85 | file.write(templates.day.html(common.entries, date)) |
86 | |
87 | for id in common.entries: |
88 | os.makedirs(output_dir + common.url_of_entry(id), exist_ok=True) |
89 | with open(output_dir + common.url_of_entry(id) + "/index.html", "w") as file: |
90 | file.write(templates.entry.html(common.entries, id)) |
91 | if "dir" in common.entries[id]: |
92 | shutil.copytree( |
93 | common.entries[id]["dir"], |
94 | output_dir + common.url_of_entry(id), |
95 | dirs_exist_ok=True, |
96 | ) |
97 | |
98 | for code in [400, 401, 403, 404, 500]: |
99 | with open(output_dir + f"/{code}.shtml", "w") as file: |
100 | file.write(templates.error.html(code)) |
101 |
Built with git-ssb-web