blob: 49932f1d4a2964b509fef8b3e1f95117dd3ed3e4 (
plain)
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
|
#!/usr/bin/env python3
import pathlib
import subprocess
import sys
content = pathlib.Path(sys.argv[1])
print("Generating footers...")
CONTACT = {
"es": "Envíame email a alex arroba corcoles punto net.",
"en": "Send me email at alex at corcoles dot net.",
}
EDIT_IN_GITHUB = {
"es": "Edita esta página.",
"en": "Edit this page.",
}
PARENT = {
"es": "Subir.",
"en": "Go to parent."
}
ENGLISH_PAGES = ('about.gmi', 'gemini.gmi',)
content_gmi_files = [str(p.relative_to(content)) for p in pathlib.Path(content).glob("**/*.gmi")]
for gmi in pathlib.Path.cwd().glob("**/*.gmi"):
relative_gmi = str(gmi.relative_to(pathlib.Path.cwd()))
if relative_gmi == "index.gmi":
# index.gmi is endless, no footer for that one
continue
language = "en" if relative_gmi in ENGLISH_PAGES or relative_gmi.startswith("notes/") else "es"
footer = []
footer.append(CONTACT[language])
content_source = None
if relative_gmi in content_gmi_files:
content_source = "blog/content/" + relative_gmi
if relative_gmi == "notes/interesting-projects.gmi":
content_source = "interesting-projects/interesting-projects.gmi"
if content_source:
footer.append(f"=> https://github.com/alexpdp7/alexpdp7/edit/master/{content_source} {EDIT_IN_GITHUB[language]}")
closest_index = gmi.with_name("index.gmi")
while closest_index == gmi or closest_index.is_relative_to(pathlib.Path.cwd()) and not closest_index.exists():
closest_index = closest_index.parent.parent / "index.gmi"
closest_index = closest_index if closest_index.exists() else None
if closest_index:
index_link = "/".join([".."] * (len(gmi.parts) - len(closest_index.parts))) + "/"
footer.append(f"=> {index_link} {PARENT[language]}")
gmi_content = gmi.read_text()
assert gmi_content.endswith("\n"), f"{gmi} has no trailing new line"
assert not gmi_content.endswith("\n\n"), f"{gmi} has extra empty blank line"
gmi.write_text(gmi_content + "\n" + "\n".join(footer) + "\n")
|