💾 Archived View for tobykurien.com › replies › 2023-04-11-re-facilitating-posting.gmi captured on 2024-05-26 at 14:42:40. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-04-19)
-=-=-=-=-=-=-
I've seen people complain that there isn't enough technical content on Gemini, so I thought: "Let's fix that!" :-P
Sender's wrote an interesting post on how they publish to their capsule:
This reminded me of a similar journey I went through with my weblog and gemlog. Initially I just had my weblog, which is a statically-generated site (using Pelican). To post, I would add a new markdown file for the new post to my locally chekout copy of my repo, run Pelican to generate the site, then scp the resulting output to my server. Since the server ran under a different user, I had multiple commands to copy, change ownership, etc. which also required typing in my sudo password multiple times. I thus enabled passwordless sudo, which is a terrible idea and gave me a reason to find a better way.
I then discovered the IndieWeb and wanted to be able to blog (or at least microblog) from my phone using the Indigenous Android app. I thus wrote a PHP script endpoint for the micropub protocol that would generate an appropriate markdown file, check it into the repo, then run the site generator and publish it.
My micropub-to-markdown PHP script
For this to work, a big change I had to make was to move the site generation to the server. With the website running under a different user, this became a challenge, until I thought of separating out the content uploading from the content publishing. The PHP script would upload images and the markdown to a $HOME/posts folder and be done. A separate process would then pickup up the files, copy them to the right place, and trigger the publishing. To co-ordinate the two, I used *inotify* to trigger the publishing process once the markdown file was written. A simplified version looks like this:
while inotifywait -e close_write $POSTS_PATH/microblog; do echo New post detected! echo Copying files... cp -R $POSTS_PATH/* $CMS_PATH/content/ cd $CMS_PATH/ echo Publishing... ./server/publish.sh echo Cleaning up... rm -rf $POSTS_PATH/microblog/* echo Done! done
The `./server/publish.sh` script simply checks in the new files, runs the generator (which now includes publishing to my gemini capsule) and copies the output to the website and gemini server folders.
This greatly simplified posting to my microblog. I even created a form on my static website that I can use to post to the same micropub endpoint (with a password) so that I can post from anywhere even without the Indigenous app.
Hopefully someone finds this useful. If so, consider subscribing, hitting that notification bell, and supporting me on my Patreon. Haha, just kidding!
__