mnot’s Web log

Design depends largely on constraints.” — Charles Eames

Monday, 15 August 2005

Putting History in Your Feed

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;

1. Link your archives together

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>
  <history:prev><$MTArchiveLink$>.rdf</history:prev>
</MTArchivePrevious>

Don’t forget to declare the namespace!

2. Link from the subscription feed to the latest archive

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.


Filed under: Syndication, Web

discussion of this entry

Mark Nottingham said…

I’ve updated this to point the prev element in the subscription feed to the correct archive.

These instructions should also work with Feed History draft -04 (the only significant change is from fh:stateful to fh:incremental, and because this example take advantage of the defaulting when fh:prev is present, no change is needed).

Sunday, September 4 2005 at 10:29 PM +10:00

add to the discussion

your details

name
e-mail address

Your e-mail address will not be shared.

your comment

Separate paragraphs with blank lines; HTML markup will be removed.

By submitting a comment, you agree to grant a limited license to reproduce it, under the same terms as the page being commented upon. If you have questions or prefer other terms, please contact me.

Creative Commons License