diff options
| -rwxr-xr-x | blog/build.sh | 11 | ||||
| -rw-r--r-- | blog/content/contact.gmi | 6 | ||||
| -rw-r--r-- | blog/content/contacto.gmi | 6 | ||||
| -rw-r--r-- | blog/content/notes/tech/how-this-site-works.gmi | 8 | ||||
| -rwxr-xr-x | blog/footers.py | 66 |
5 files changed, 88 insertions, 9 deletions
diff --git a/blog/build.sh b/blog/build.sh index d7bce2b6..bfad6400 100755 --- a/blog/build.sh +++ b/blog/build.sh @@ -8,19 +8,17 @@ HERE=$(pwd) rm -rf $TARGET cp -a content/ $TARGET +echo Generating notes/interesting-projects python3 ../interesting-projects/interesting-projects.py >$TARGET/notes/interesting-projects.gmi -echo Converting gmi to html... - cd $TARGET -find . -name '*.gmi' -print0 | xargs -0 coppewebite-to-html --css $HERE/style.css echo Generating index... cat >index.gmi <<EOF # El blog es mío ## Hay otros como él, pero este es el mío -Envíame email a alex arroba corcoles punto net. +=> /contacto Contacta conmigo. => notas/ Notas => notes/ Notes @@ -31,7 +29,10 @@ find . -path './2???/??/*.gmi' -type f -print0 | coppewebite-indexer . >>index.g echo Generating RSS... coppewebite-to-rss <index.gmi https://alex.corcoles.net . >index.rss -echo Converting index to HTML... +$HERE/footers.py $HERE/content + +echo Converting to HTML +find . -name '*.gmi' -print0 | xargs -0 coppewebite-to-html --css $HERE/style.css coppewebite-to-html index.gmi --feed-title "El blog es mío" --feed-href index.rss --css $HERE/style.css echo Done diff --git a/blog/content/contact.gmi b/blog/content/contact.gmi new file mode 100644 index 00000000..8b06813d --- /dev/null +++ b/blog/content/contact.gmi @@ -0,0 +1,6 @@ +# Contact + +Send me email to alex at corcoles dot net. +=> https://i.delta.chat/#F39B6A2BB323992DB8B897D2B3AD081B56A5FAC6&a=vmupyibe9%40nine.testrun.org&n=Alex2&i=84tOryYQa6e-2qD75_LE5X-r&s=JlQQAedymqJC8rwkSaMC4oa7 Send me a message with Delta Chat +=> https://alex.femto.pub/@coder@alex.femto.pub/ Read me in the Fediverse at @coder@alex.femto.pub +Send me a message with XMPP/Jabber to koalillo at conversations dot im. diff --git a/blog/content/contacto.gmi b/blog/content/contacto.gmi new file mode 100644 index 00000000..a074738d --- /dev/null +++ b/blog/content/contacto.gmi @@ -0,0 +1,6 @@ +# Contacto + +Envíame email a alex arroba corcoles punto net. +=> https://i.delta.chat/#F39B6A2BB323992DB8B897D2B3AD081B56A5FAC6&a=vmupyibe9%40nine.testrun.org&n=Alex2&i=84tOryYQa6e-2qD75_LE5X-r&s=JlQQAedymqJC8rwkSaMC4oa7 Envíame un mensaje por Delta Chat. +=> https://alex.femto.pub/@yo@alex.femto.pub/ Léeme en el Fediverso en @yo@alex.femto.pub +Envíame un mensaje por XMPP/Jabber a koalillo arroba conversations punto im diff --git a/blog/content/notes/tech/how-this-site-works.gmi b/blog/content/notes/tech/how-this-site-works.gmi index eafbe7bf..0b0a33b7 100644 --- a/blog/content/notes/tech/how-this-site-works.gmi +++ b/blog/content/notes/tech/how-this-site-works.gmi @@ -19,13 +19,13 @@ The Gemini protocol suite of protocols also describes a way to derive a feed fro ## Static site generation -As a first step, a process converts every foo/bar.gmi file to a foo/bar.html HTML file. +=> https://github.com/alexpdp7/coppewebite/tree/main/gemini-to-web Besides the scripts specific to this blog, a big part of the job is converting gemtext to HTML and RSS, which is done by the generic gemini-to-web tools in my coppewebite suite of Gemini software. -=> https://github.com/alexpdp7/coppewebite/tree/main/gemini-to-web This is done with the coppewebite-to-html command part of my coppewebite suite of Gemini tools. +First, the root index.gmi is generated. The header is a static gemtext snippet. Then, coppewebite-indexer generates a series of links in chronological order to the articles in YYYY/MM/article.gmi files that follows the header. The series of links is an implicit gemtext feed, which the coppewebite-to-rss tool converts to RSS. index.gmi and index.rss both have an implicit gemtext feed and an RSS feed. -Then, the root index.gmi is generated. The header is a static gemtext snippet. Then, coppewebite-indexer generates a series of links in chronological order to the articles in YYYY/MM/article.gmi files that follows the header. +Then, a 70-line Python script adds a footer to most pages. Footers contain links for navigation, editing, and contact. -The series of links is an implicit gemtext feed, which the coppewebite-to-rss tool converts to RSS. index.gmi and index.rss both have an implicit gemtext feed and an RSS feed. Using coppewebite-to-html again, index.gmi is converted to index.html containing metadata embedding the feed. +Finally, another gemini-to-web tool converts every foo/bar.gmi file to a foo/bar.html HTML file, adding RSS feeds to pages with embedded gemtext feeds. The result is a directory with .html, .gmi, and .rss files, including index.html, index.rss, index.gmi, but also notes/tech/how-this-site.works.html and .gmi. diff --git a/blog/footers.py b/blog/footers.py new file mode 100755 index 00000000..ca0977ae --- /dev/null +++ b/blog/footers.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +import pathlib +import subprocess +import sys + +content = pathlib.Path(sys.argv[1]) + +print("Generating footers...") + +CONTACT = { + "es": "=> {relative_root}/contacto Contacta conmigo.", + "en": "=> {relative_root}/contact Contact me.", +} + +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', "contact.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 = [] + + 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)) + + 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") |
