diff options
Diffstat (limited to 'blog/footers.py')
| -rwxr-xr-x | blog/footers.py | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/blog/footers.py b/blog/footers.py index 137bafd6..ca0977ae 100755 --- a/blog/footers.py +++ b/blog/footers.py @@ -8,8 +8,8 @@ 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.", + "es": "=> {relative_root}/contacto Contacta conmigo.", + "en": "=> {relative_root}/contact Contact me.", } EDIT_IN_GITHUB = { @@ -17,7 +17,12 @@ EDIT_IN_GITHUB = { "en": "Edit this page.", } -ENGLISH_PAGES = ('about.gmi', 'gemini.gmi',) +PARENT = { + "es": "Subir.", + "en": "Go to parent." +} + +ENGLISH_PAGES = ('about.gmi', 'gemini.gmi', "contact.gmi",) content_gmi_files = [str(p.relative_to(content)) for p in pathlib.Path(content).glob("**/*.gmi")] @@ -31,14 +36,29 @@ for gmi in pathlib.Path.cwd().glob("**/*.gmi"): footer = [] - footer.append(CONTACT[language]) + relative_root = "/".join([".."] * (len(gmi.parts) - len(pathlib.Path.cwd().parts) - 1)) + + if relative_gmi not in ("contact.gmi", "contacto.gmi"): + footer.append(CONTACT[language].format(relative_root=relative_root)) - edit_url = None + content_source = None if relative_gmi in content_gmi_files: - edit_url = "https://github.com/alexpdp7/alexpdp7/edit/master/blog/content/" + relative_gmi + 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" - if edit_url: - footer.append(f"=> {edit_url} {EDIT_IN_GITHUB[language]}") + 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" |
