Published: 06.05.2021 | Edited: 09.05.2021 | Tags: 100daystooffload,journal
My blog has a Feed now!
A few days ago, Ru asked me if the RSS on my blog is available.
Hint: it wasn't.
Go check Ru's work by the way. She is actually investing a lot of thoughts into whatever she's doing, so expect to find something worthwhile around her.
But the fact is, this blog's feature list is very slim, mainly because I am trying to build the blog without the database - it is based entirely around git and generated statically. The resulting workflow of such setup suits my command line addiction, but I have to balance between hacking on the blog and creating the actual content. You may guess which one of these two activities I totally avoid most of the year.
Anyway, an Atom or RSS feed is a pretty indispensable feature, so I went on squeezed some time in for an actual implementation, as I there were no excuses left for not having one at this point.
The bulk of the work for RSS on Sapper (a part of Svelte ecosystem) has been documented at lacourt.dev and it was tailored for Atom further at dev.to. I have chosen to implement Atom over RSS 1.0 or RSS 2.0, because Atom is a defined IETF standard meaning it is less likely to change unexpectedly, providing a potential for a long term stability.
The structure of the RSS file is XML, meaning it will not readily accept HTML. My HTML is automatically generated, so I tried tweaking some parameters, trying to make the generated HTML as compliant at as possible. After I resolved chain of few errors I got stuck, so I went looking for a different way.
The HTML can of course be included in XML and there are at least two common ways to do so. One is to encode the content in Base64 encoding and the other is to use CDATA tag. I went with CDATA as I could not find if RSS clients decode Base64 automatically or there is some way to tell them to do so. Also, way CDATA is more verbose, meaning expecting the generated RSS file manually I can see what is going on straight away.
I have also discovered that there is a library for feeds called xast-util-feed already and it is a part of unified.js ecosystem. I use many components they provide for markdown to HTML transformation and this could be used readily as well. I might use that in the future as a part of optimizations. Currently the file itself is probably over 1 MB large and it is shipping all the CSS classes and other similar stuff that might not be needed, so there is definitely some room for improvement.
Finally, I did provide categories as a concatenated string for now as many my posts do not have a clear category and I plan to rework that a little bit in the near future, so expect some changes in this area as well. Also deciding if I should provide only excerpt of the full post was easy for me and Kev covered it on his blog post precisely, clearing any doubts.
The feed should be automatically discovered via
peterbabic.dev, but if not, the route to it is at https://peterbabic.dev/rss. Enjoy!
This is a 57th post of #100daystooffload.