Adding an RSS Feed to Neocities

Adding an RSS Feed to Neocities

#0003



As an avid user of RSS for newsfeeds and Reddit (which is sadly sunsetting RSS), this was a high-priority feature for me to add to the site. I was pleasantly surprised that, for once, this was easier than I had hoped.


I'd like to note that I am going to avoid over-explaining my methodology and code here. I feel like my particular use-case is somewhat atypical. If you have a basic understanding of HTML, JS, Python, and Bash (and have access to CLI tools), you are likely savvy enough to understand my code. If you aren't, there are frankly more simple methods of doing this that would take less time to implement. Consider checking out this or this if you fall into the latter category.


I've previously attempted this with third-party services and plug-ins with varying success. I will admit I cringed a bit after discovering that the typical advice for implementing this on Neocities was to do it by hand.


Fortunately, I had already been formatting my posts in such a way that made this very easy to implement. My blog posts are all saved as separate HTML files and include the basic metadata needed for RSS. All that I had to do was scrape that information and format it into an XML file.



Given the limitations of Neocities, if I don't want to literally do this by hand, any automation will have to be done outside of the host server. It was simple enough to make a python script (rss.py) to scrape the metadata from the individual posts and compile the XML file (feed.xml).


Note: I didn't add support for thumbnail images because Neocities has been weird about hotlinking images. Images within the post body seem to work fine, so this may not be a problem. I also don't feel like editing thumbnails to be consistently sized. Adding thumbnails and categories would be a quick upgrade if they end up being needed.


Technically we're already done. The RSS feed is made: mission accomplished. However, I still found the idea of having to manually maintain an offline copy of my posts and uploading the XML file to be a bit inconvenient.


Much to my relief, Neocities offers SFTP access. This means I can run a simple Bash script (RSS_gen.sh) to download the posts, run rss.py, and upload the XML file to my web server. Most of my time on this went to rememberimg that I had to do a one-time manual connection to SFTP through the CLI to get the prompt from the server to approve the connection. I very rarely use CLI for FTP.


After a quick check with the W3C RSS validator, I now have a shiny new RSS feed that is ready to serve. This is as simple as making a link to the XML file on my site index (like this). It was an almost disorienting change of pace to have this work the first time I added it to my RSS reader.


I decided to take this one step further and write a JS script to parse feed.xml and render it back into HTML to use as an index of my posts. There are almost definitely better ways of doing this, but this works for now.



Next steps will be getting my feed indexed by other sites. There are numerous sites devoted just to indexing other users' RSS feeds; most of which just require you to submit your link. I should probably work on getting some more content on the site before I bother doing that though.

Webmentions