4.3. Producing RSS 2.0 with Blogging Tools
The vast majority of RSS 2.0 feeds are produced by weblogging tools that use templates. The most popular of these is Movable Type, written by Ben and Mena Trott, which is freely available for personal use at http://www.movabletype.org. In order to discuss a few important implementation points, Example 4-3 shows a template for Movable Type that produces an RSS 2.0 feed.
Example 4-3. A Movable Type template for producing RSS 2.0
<?xml version="1.0"?> <rss version="2.0"> <channel> <title><$MTBlogName$></title> <link><$MTBlogURL$></link> <description><$MTBlogDescription$></description> <language>en-gb</language> <copyright>All content Public Domain</copyright> <managingEditor>firstname.lastname@example.org</managingEditor> <webMaster>email@example.com</webMaster> <docs>http://blogs.law.harvard.edu/tech/rss</docs> <category domain="http://www.dmoz.org">Reference/Libraries/Library_and_Information_ Science/Technical_Services/Cataloguing/Metadata/RDF/Applications/RSS/</category> <generator>Movable Type/2.5</generator> <lastBuildDate><$MTDate format="%a, %d %b %Y %I:%M:00 GMT"$></lastBuildDate> <ttl>60</ttl> <MTEntries lastn="15"> <item> <title><$MTEntryTitle encode_html="1"$></title> <description><$MTEntryExcerpt encode_html="1"$></description> <link><$MTEntryLink$></link> <comments><$MTEntryLink$></comments> <author><$MTEntryAuthorEmail$></author> <pubDate><$MTEntryDate format="%a, %d %b %Y %I:%M:00 GMT"$></pubDate> <guid isPermaLink="false">GUID:<$MTEntryLink$></g<$MTEntryDate format= "%a%d%b%Y%I:%M"$></guid> </item> </MTEntries> </channel> </rss>
The vast majority of this template is standard Movable Type fare. Taken from one of my own blogs, it uses the <$MT$> tags to insert information directly from the Movable Type database into the feed. So far, so simple.
Two things are worth close examination. First, the date format:
<pubDate><$MTEntryDate format="%a, %d %b %Y %I:%M:00 GMT"$></pubDate>
Care must be taken to ensure that the format of the contents of the date fields are correctly formed. RSS 2.0 feeds require their dates to be written to comply with RFC 822for example: Mon, 03 Jan 2002 0:00:01 GMT.
Common errors found in RSS 2.0 feeds include missing commas, seconds values, and time zones. You must ensure these are all present because some desktop readers and aggregators aren't as forgiving as others, and many are getting less so as they develop.
Implementation of the guid element is equally important. The RSS 2.0 standard doesn't discuss the form of the guid; it only asks the author to ensure that it is globally unique. There is no scope for the OSF GUID standard to be used within most blogging tools, so you have to formulate your own system. (I'll touch upon this again when we talk about Atom in Chapter 7.)
For the template shown earlier, I considered various things. First, the guid's purpose is to tell applications if the entry is new or if it has changed. Second, within my own blogs I allow people to add comments to the entries. I consider this a change to the entry, so my guid must reflect this. Because this change isn't reflected in the link to the entry, the link alone isn't a good guid. So, by combining the link with the last-updated-date value, I can make a guid that is globally unique and changes when it needs to. For added measure, I add the string GUID to the front of it to prevent it from looking too much like a retrievable URLwhich, of course, it isn't. Hence:
<guid isPermaLink="false">GUID:<$MTEntryLink$></g<$MTEntryDate format= "%a%d%b%Y%I:%M"$></guid>
This works well as an RSS 2.0 guid, but it has one feature that might annoy: because weblog comments cause the guid to change, it also causes the item to be marked as unread in many feed aggregators. This might not be desirable behavior for you.