In part one I created this site. In this post i describe how i added an RSS feed.

First off what and why? RSS stand for Really Simple Syndication. I'm not sure what that means but it's simply a standardized way of sharing a feed of information. It is simply a XML formated text file like HTML. It has some different naming convensions that you must follow for it to comply. The full specification can be found here.

The reason to do this is to provide a subscription mechanism for aggregators and users who want to be notified of content changes. I personally subscribe to a couple of different blogs with a chrome extension called Feeder.

Before my feed was stored in a json file with arbitrary naming. Changing over to XML format is not as trivial as changing the file extension. Before i simply used import to import the javascript Object directly from a json file. This is not nativly supported for xml for some reason.

import posts from "../../static/posts.json" assert { type: "json" };

Denoland to the rescue! MikaelPorttila has made a XML parser that parses all RSS to a common Javascript Object format. Deno is a global keyword that has a bunch of useful OS interactions, including file reading.

import { parseFeed } from "https://deno.land/x/rss/mod.ts";
const xml = await Deno.readTextFile(`./static/posts.xml`);
const feed = await parseFeed(xml);

This is an example of the object:

{
  type: "RSS 2.0",
  id: "https://saket.dk",
  title: { value: "saket.dk", type: undefined },
  description: "Soren Sakets Personal blog about Web, Application and Game Development",       
  language: "en-US",
  links: [ "https://saket.dk" ],
  entries: [
    {
      id: "meta-blog-2",
      title: { value: "Adding RSS feed to the blog", type: undefined },
      description: { value: "Process of adding an RSS Feed to the blog", type: undefined },    
      comments: undefined,
      published: 2022-07-05T22:00:00.000Z,
      publishedRaw: "07/06/2022",
      updated: 2022-07-05T22:00:00.000Z,
      updatedRaw: "07/06/2022",
      author: { email: undefined, name: "saketsoren@gmail.com (Soren Saket)", uri: undefined },
      links: [ [Object] ],
      categories: [ [Object], [Object], [Object] ],
      contributors: undefined
    }
  ]
}

It was actually not that hard 🥳. I just create a Handler that returns the Feed object and use the data accordingly. Now you can go subscribe !