git ssb

0+

Grey the earthling / gkn.me.uk



Tree: 6274ace7f16374fb0f42a3689ff0dbef1a839241

Files: 6274ace7f16374fb0f42a3689ff0dbef1a839241 / generator / generate.py

3840 bytesRaw
1import os
2import shutil
3
4import common
5import templates.index
6import templates.entries
7import templates.series
8import templates.tag
9import templates.year
10import templates.month
11import templates.day
12import templates.entry
13import templates.error
14
15
16output_dir = "output"
17
18shutil.rmtree(output_dir, ignore_errors=True)
19shutil.copytree("static", output_dir, dirs_exist_ok=True)
20
21os.makedirs(output_dir, exist_ok=True)
22
23for 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
39os.makedirs(os.path.join(output_dir, "style/fonts/smol-emoji"), exist_ok=True)
40shutil.copy(
41 os.path.expanduser(f"~/Software/src/smol-emoji/SmolEmoji-Regular.otf"),
42 os.path.join(output_dir, "style/fonts/smol-emoji"),
43)
44shutil.copy(
45 os.path.expanduser(f"~/Software/src/smol-emoji/LICENSE"),
46 os.path.join(output_dir, "style/fonts/smol-emoji"),
47)
48
49with open(output_dir + "/index.html", "w") as file:
50 file.write(templates.index.html(common.entries))
51
52os.makedirs(output_dir + "/entries", exist_ok=True)
53with open(output_dir + "/entries/index.html", "w") as file:
54 file.write(templates.entries.html(common.entries))
55with open(output_dir + "/feed", "w") as file:
56 file.write(templates.entries.atom(common.entries))
57
58for 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
65for 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
72for 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
77for 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
82for 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
87for 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
98for 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