text/gemini
# A GMI-based Atom feed generator
The convention for serving blog/gemlog feeds seems to be Atom+XML, and looking round at the options so far for generating these, there is a Python script or otherwise folks are just writing them by hand.
I'm avoiding installing Python for now on my sparse machine, and the thought of writing Atom XML by hand each time I write a post makes my left eye twitch.
And besides do you want to have to run a command line as an additional step every time you just write some content?
Whilst in these early days of Gemini, techno-savvy early adopters are probably comfortable accessing a machine on the command line, eventually a wider base of Gemini users will just want to upload their blog post using SFTP or some other even simpler upload interface and be done.
## Automatic feed generation
To this end, I realised that a practical solution for authors would be to have an automatic feed generator that uses a text/gemini file as its starting point - the existing blog index file. This blog index, updated by the author as they progress, is a natural way for authors to list out and describe their blog posts for human visitors to the site. The script reads the same file so the live feed is automatically up to date. No need to log into the machine and run a commandline script - just upload the post file and updated blog index. Your human and robot audience will both be able to find them.
Whilst I've written this version in Rebol, actually the script is very simple and the design could be easily implemented in other languages if you want to adapt it.
This is all fairly straightforward due to the simplicity and parsing strengths of Rebol and the fact that text/gmi is a simple line based format. This fundamental design choice of Gemini is going to prove fruitful for so many light weight parsing situations like this. Thanks Solderpunk and friends.
## Feed format
The author writes their blog posts in the usual way and creates a link in their blog index underneath their gemini visible folder. This blog index can be linked to from their home page and read by normal human visitors.
The CGI script reads this same blog index file, and parses it as follows.
If there is a Heading 1 it becomes the title of the feed listing, otherwise a generic title is used.
```
# My blog title
```
The list of links are scanned, and those that have a display text of the form "datetitle" are taken to be the blog entries. Any other links are ignored.
```
=> secondpost.gmi 2020-7-1 My second blog post
=> firstblogpost.gmi 22-Jun-2020 My first blog post
=> ignoreme.gmi This one is ignored as it doesnt start with a date
```
The titles are also normalised/simplified to remove hyphens and underscores, so you can put a natural hyphen between the date and title:
```
=> thirdpost.gmi 2/7/2020 - A third post, hyphen will be removed
```
The date format is fairly flexible and anything that passes the 'to-date' function will be fine, such as the examples above.
The final url is assembled by appending the link target onto the blog base url.
All other lines are ignored in building the feed.
## Per-user feeds
The design allows for many users on the same machine to make use of the feed generator. In the script there is a list of known users, which allows each of them to have their own gemlog file and base url and timezone.
```Rebol
;---extend as necessary with other users
users: context [
lukee: context [
gemlog-path: %/var/gemini/blog/index.gmi
base-url: "gemini://gemini.marmaladefoo.com/blog/"
author-name: "Luke Emmet"
author-email: "luke@marmaladefoo.com"
timezone: "Z"
]
]
```
Then the username is passed to the CGI script to generate the feed for that user:
```
=> gemini://domain/cgi-bin/atom-feed.cgi?lukee Atom feed for lukee
=> gemini://domain/cgi-bin/atom-feed.cgi?username2 Atom feed for username2
... and so on
```
And the resultant url submitted to Capcom or linked from the users blog page.
Alternatively the script could be extended to programmatically look up this information if there is a common layout and convention on the machine.
## Example
This site, Marmaladefoo, uses this script for its feed generator:
=> /blog/index.gmi Human readable blog index
=> /cgi-bin/atom-feed.cgi?lukee Generated Atom feed
## Installation/Source
You will need Rebol on your machine, and a CGI compatible Gemini server.
=> https://github.com/LukeEmmet/GMIToAtomFeed GMIToAtomFeed source in Github
______________ ______________ ______________
=> / Home
This content has been proxied by September (ba2dc).