mnot’s blog

Design depends largely on constraints.” — Charles Eames

Monday, 15 August 2005

Putting History in Your Feed

Filed under: Syndication Web

I’ve had a few e-mails asking how I got this site’s RSS feed to include its history, so here are the instructions for doing it in Moveable Type (the software that I use to manage this site). If you have instructions for other feed-generating software, please either leave them in comments below, or send me an e-mail.

In a nutshell, there are two easy steps;

The feed needs to be archived for it to have a history; for most blogs, the most convenience way to do this is to periodically archive; for example, this site’s feed is archived monthly, but a higher-volume feed might be archived weekly or even daily.

In Moveable Type, you do this by creating a new archive (in Weblog Config -> Archiving) that uses RSS or Atom as the format, rather than HTML. This site’s date-based RSS template is one example.

Then, each of the archives needs to be declared as such, with the history:archive element, and linked to the previous one in the header of the feed archive; for example, May’s archive on this site is linked to April’s like this;

<history:archive/>
<history:prev>http://www.mnot.net/blog/2005/04/index.rdf</history:prev>

The code to add to the Moveable Type template’s head section is very simple;

<history:archive/>
<MTArchivePrevious&gt
  <history:prev><$MTArchiveLink$>.rdf</history:prev>
</MTArchivePrevious>

Don’t forget to declare the namespace!

Then, you need to link to the latest archive from the main (or “subscription”) feed. In MT, you do it like this;

<MTArchiveList archive_type="Monthly" lastn="1">
  <MTArchivePrevious><MTArchivePrevious>
    <state:prev><$MTArchiveLink$>.rdf</state:prev>
  </MTArchivePrevious></MTArchivePrevious>
</MTArchiveList>

Note that there are two MTArchivePrevious elements; this is because the most recent archive is in fact this month’s, when we need last month’s.

While you’re in there, make sure you adjust the main feed so that always contains the entries that have been added since the last archive, so that a client that’s trying to re-build your feed’s history doesn’t miss any entries. Since my feed is archived monthly, I’ve adjusted my subscription feed to contain all entries from the last 31 days.

If your feed has more traffic (e.g., many entries in a week or a day), you should make the archive period correspondingly smaller (perhaps weekly, or even daily for high-traffic sites), so that your subscription feed doesn’t get too big. That way, your clients can not only reconstruct your feed’s state, but you save bandwidth too.

See this site’s subscription feed template for an example.


1 Comment

Creative Commons