joeldueckdotcom

RSS Library for Racket

This a nascent Coding and publishing project. No one else has made this yet, and it’s something I’ve had to do manually more than once.

This package is now available as a beta: https://github.com/otherjoel/splitflap

Original notes

Purposes (in order of importance and implementation):

  1. Convenient generating of valid, best-practice Atom 1.0 feeds suitable for blogging.
  2. Same, but for podcast feeds
  3. Parsing RSS feeds
  4. Validating RSS feeds. (This might never happen. The W3C already has a reference validator, though a Racket implementation might be an interesting exercise.)

Design

You should only have to supply what is absolutely necessary to generate the elements required by the spec.

Everything you supply is validated, so the result is always either a valid feed or an exception.

The library will actually be a bit more opinionated than the spec about how your feed is constructed. This supports the convenience aspect because you have fewer decisions to make, and the validation aspect because there are fewer problems to look for.

Useful links

Example

The below is a near-verbatim excerpt from the test suites that I have passing so far:

#lang racket

(require feed)

(define me      (person "Kate Poster" "kate@example.com")
(define site-id (mint-tag-uri "example.com" "2007" "blog"))

(define entry-1
  (parameterize ([current-timezone 0])
    (feed-entry (append-specific site-id "one")
                "https://example.com/blog/one.html"
                "Kate's First Post"
                me
                (infer-moment "2007-03-17") ; published
                (infer-moment "2007-03-17") ; updated
                `(div (p "Welcome to my blog.") ))))

(define blog-feed 
  (feed site-id "https://example.com/" "Kate Poster Posts" (list entry-1)))

(express-xml blog-feed 'atom "https://example.com/feed.atom")

Running that code results in:

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Kate Poster Posts</title>
  <id>tag:example.com,2007:blog</id>
  <link rel="self" href="https://example.com/feed.atom" />
  <link rel="alternate" href="https://example.com/" />
  <updated>2007-03-17T00:00:00Z</updated>
  <entry>
    <title type="text">Kate&apos;s First Post</title>
    <id>tag:example.com,2007:blog.one</id>
    <link rel="alternate" href="https://example.com/blog/one.html" />
    <author>
      <name>Kate Poster</name>
      <email>kate@example.com</email>
    </author>
    <updated>2007-03-17T00:00:00Z</updated>
    <published>2007-03-17T00:00:00Z</published>
    <content>
      <![CDATA[<div><p>Welcome to my blog.</p></div>]]>
    </content>
  </entry>
</feed>