💾 Archived View for cwave.site › gemlog › 2024-05-02.gmi captured on 2024-05-26 at 14:32:27. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2024-05-10)

-=-=-=-=-=-=-

Homepage updater script

I made a script to copy the five most recent entries from gemlog/index.gmi to index.gmi (the home page), so that I don't have to add new ones to two indices and take old ones off by hand. It looks like this

#!/bin/bash

cd /home/pi/gemini/scripts/
sed -n '/{#RECENT#}/!p;//q' ../index.draft > ../index.gmi
grep -E -m 5 "^(=>\s[0-9])" ../gemlog/index.gmi >> ../index.gmi
sed -n '1,/{#RECENT#}/!p' ../index.draft >> ../index.gmi
sed -i -E "s/^(=>\\s)([0-9])/\1\\gemlog\/\2/g" ../index.gmi

where ``../gemlog/index.gmi`` contains links to daily pages in reverse order and the link text / file name is always the date; the grep line fetches the first 5 lines of the form "=> 2..." from this file.

I now edit my homepage in ``index.draft``, it looks like

...

## Gemlog
=> gemlog/ All posts
### Recent posts
{#RECENT#}

...

The script goes around and copies everything from index.draft to index.gmi, replacing the {#RECENT#} placeholder with the five link lines. I made a cron job to do this every hour. This also means that my edits to my homepage don't appear online immediately; the script "publishes" them for me hourly.

This sed and awk stuff was a pain in the ass for more than an hour. I first tried replacing with sed, but there was lots of trouble with quotes and newline. Should have just used python.

Edit:

And the last line

sed -i -E "s/^(=>\\s)([0-9])/\1\\gemlog\/\2/g" ../index.gmi

was added to fix the links by inserting relative directory gemlog/ . This is fine as long as there are no other links on homepage starting with dates or numbers, which really do live directly in home folder.

I could assume this blog won't still be running the next millenium, and narrow it down to links starting with "2".

Back to gemlog index

Back to coldwave's home