quick search:
 

Improved RSS for Plone

Submitted by: martinb
Last Edited: 2004-10-14

Category: CMF

Average rating is: 4.0 out of 5 (1 ratings)

Description:
Many people wanting to provide an RSS feed of a folder will be using it to syndicate some kind of news or Blog, and will generally want their feed sorted by reverse date. The standard CMF RSS feed doesn't do this - it sorts by ID, which isn't all that much help. The documentation waves a hand at resolving this, leaving it as an exercise.

Here's my resolved version.


Source (Text):
<?xml version="1.0"?>

<rdf:RDF
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  xmlns="http://purl.org/rss/1.0/"
>
<channel rdf:about="<dtml-var absolute_url>">
  <title>&dtml-Title;</title>
  <link>&dtml-portal_url;</link>
  <description>
    &dtml-Description;
  </description>

  <image rdf:resource="logo.png" />
<sy:updatePeriod><dtml-var expr="portal_syndication.getUpdatePeriod(this())"></sy:updatePeriod>
<sy:updateFrequency><dtml-var expr="portal_syndication.getUpdateFrequency(this())"></sy:updateFrequency>
<sy:updateBase><dtml-var expr="portal_syndication.getHTML4UpdateBase(this())"></sy:updateBase>

<dtml-comment>Start Items Elements</dtml-comment>
  <items>
    <rdf:Seq>
<dtml-let max_items="portal_syndication.getMaxItems(this())">
<dtml-in expr="portal_syndication.getSyndicatableContent(this())" reverse
         sort="CreationDate" size="max_items" orphan="1" skip_unauthorized>
 <dtml-let obj="_.getitem('sequence-item', 0 )">
<rdf:li resource="<dtml-var absolute_url>" />

 </dtml-let>
</dtml-in>
</dtml-let>
   </rdf:Seq>
  </items>
</channel>
<dtml-comment>End Items Elements</dtml-comment>

<dtml-comment>Start Item Elements</dtml-comment>
<dtml-let max_items="portal_syndication.getMaxItems(this())">
<dtml-in expr="portal_syndication.getSyndicatableContent(this())" reverse
         sort="CreationDate" size="max_items" orphan="1" skip_unauthorized>
 <dtml-let obj="_.getitem('sequence-item', 0 )">
<dtml-var expr="itemRSS(obj)">
</dtml-let>
</dtml-in>
</dtml-let>
<dtml-comment>End Item Elements</dtml-comment>
</rdf:RDF>

Explanation:
The RSS feed template comprises two parts - one which is the RSS content for each item (rssItem), and a wrapper which defines the skeleton of the XML and selects the items to use. This is the one you want.

Add a dtml method to your custom folder with id <code>rssItem</code>, with the above code. This will replace the standard RSS skeleton.

It works by changing the standard dtml-in to
a) Sort by CreationDate (you could alternatively use ModificationDate)
b) reverse the sort to put the most recent items first.

The main lesson to learn from this is to work harder at defining your users' requirements before sitting down to code a tool.

The above has been tested on Plone1.01 and the output is visible at http://easyweb.co.uk/Members/martin/blog/RSS


Comments:

rssItem? by georgeh - 2004-10-14
In my Plone (1.0.3) I'm seeing the file to modify as rssBody in ${portal_url}/
portal_skins/generic/rssBody