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