git ssb

0+

Grey the earthling / gkn.me.uk



Tree: 305411b620accbb0d285152dac313c556e5c02c3

Files: 305411b620accbb0d285152dac313c556e5c02c3 / generator / generate.py

3794 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.copytree("static", output_dir, dirs_exist_ok=True)
19
20os.makedirs(output_dir, exist_ok=True)
21
22for font in ["iosevka-grey", "iosevka-grey-mono"]:
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
38os.makedirs(os.path.join(output_dir, "style/fonts/smol-emoji"), exist_ok=True)
39shutil.copy(
40 os.path.expanduser(f"~/Software/src/smol-emoji/SmolEmoji-Regular.otf"),
41 os.path.join(output_dir, "style/fonts/smol-emoji"),
42)
43shutil.copy(
44 os.path.expanduser(f"~/Software/src/smol-emoji/LICENSE"),
45 os.path.join(output_dir, "style/fonts/smol-emoji"),
46)
47
48with open(output_dir + "/index.html", "w") as file:
49 file.write(templates.index.html(common.entries))
50
51os.makedirs(output_dir + "/entries", exist_ok=True)
52with open(output_dir + "/entries/index.html", "w") as file:
53 file.write(templates.entries.html(common.entries))
54with open(output_dir + "/feed", "w") as file:
55 file.write(templates.entries.atom(common.entries))
56
57for 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
64for 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
71for 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
76for 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
81for 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
86for 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
97for 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