Greg's Thoughts


Adding an RSS Feed with my Dewblog framework

I added an RSS feed on my blog. Most feed readers will find it already, but in case you're curious the feed can be found at rss.xml.

Adding the RSS feed with my dewblog framework was simpler than I expected.

For most content, I create a page-title.page file. This file has the title, content and created date for the page content, but in the case of an RSS feed, the most important part is all of the other pages. I'd already solved this problem when I implemented tags though, so the work in the renderer was already done.

Let's take a look at the RSS page file:

---
title: Greg's Thoughts
root: https://glaka.us
summary: Welcome! I'm Greg, and this is a blog about my projects, ideas and thoughts. I post about problems I find interesting in software engineering, programming, D&D, and around the internet.
ext: .xml
template: rss.tmpl
hide: true
---

Note that there's no actual content written down. It has a title for the RSS feed, overrides the extension of the rendered file (to .xml), and marks the page as "hidden" so that it doesn't get dumped into the regular indexed list. Nothing references the other content, though.

Unlike the other pages, all of the content of the feed is rendered out by the template.

<rss version="2.0">
<channel>
<title>{{.Title}}</title>
<link>{{.Parameters.root}}/rss.xml</link>
<description>{{.Parameters.summary}}</description>
{{- $root := .Parameters.root }}
{{- range $index, $page := .AllPages }}
    {{- if not $page.Parameters.hide }}
    <item>
        <title>{{.Title}}</title>
        <link>{{$root}}/{{.Path}}</link>
        {{- if .Parameters.summary}}<description>{{.Parameters.summary}}</description>{{end}}
        {{- if .Parameters.created}}<pubDate>{{.Created.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</pubDate>{{end}}
    </item>
    {{- end}}
{{- end}}
</channel>
</rss>

It's pretty short, but builds a list of all of the posts I have.

The created date is presented to the template as a Time object, we can use the Time.Format function to format the timestamp in the way my RSS reader expects, which is different than the way it can be formatted elsewhere, and different than the format in the page files. According to the spec I found (which is harvard law for some reason?), the timestamp should be RFC822. My feed reader wasn't picking up the timestamp though. Most RSS feeds I saw use RFC1123; so I went with that. It didn't work.

I learned that the XML is very unforgiving, I initially used <pubdate> instead of <pubDate>, which erased the timestamp entirely in my client. Once that's all fixed, my feed reader picked up the posts in the right order and with the right dates and all. Hooray!

That does it for today. What I'm thinking of working on next is making the source code available, but I need to find the right home for it.