Search:

Welcome

Login to contribute. Register if you haven't yet.

Need Support?

Search this site to find an answer. If you still need help, post a Question. Private or account-related support inquiries can be made at the Private Support forum.

How to code custom RSS feeds for page level updates?

Q. [geofff - Mar 11, 2008] This is a followup to Woody's question back in December. I also need to code custom RSS feeds for page level updates. The tutorials on using raw pages is great; but I still can't quite figure out how to get update info through the implicit objects. The page object doesn't seem to know anything about prior versions of itself, and the site object doesn't have a method for retrieving all updates that might be similar to the external rss.xml feed. I tried to grab the site feed and post-process it myself (i.e., remove all <item> nodes that don't match the target page) using this syntax:

var rss = site.getPage('rss.xml');

but I guess the feed doesn't really exist as a Page class object. Is there another way at getting at the data in the feed? Or is there a method available to server-side js that allows me to open an external url?

Thanks very much -- I've only been using EditMe for a couple of days, but I'm already really impressed! 

A. [matt] Unfortunately, this is currently a hole in the API - there is no way to get page version data or the recent changes list. You can read the site's RSS feed for post processing using the (until-now-undocumented) util.httpGet(..) method. I'll add a suggestion about API access to page versions.

Followup. [geofff -  Mar 13, 2008] Thanks, Matt! Not sure if this is the right place to post this, but I wrote a quick-n-dirty function for this based on the excellent PageToXML example:

function rssFor(p) {
  var rss = util.httpGet(server.domain,"/rss.xml");
  var rssDoc = util.parseXML(rss);
  var items = rssDoc.rootElement.selectNodes("//item");
  var target = "http://" + server.domain + "/" + p;
  for each (var item in items) {
    if (item.element("link").text != target) {
      item.detach();
    }
  }
  return rssDoc.asXML();
}

Just like PageToXML, I have this script in my SharedFunctions page, and it is called from another page called RSSFor with a get param "page" to indicate the target. (A couple of notes on the function: 1) I couldn't get the more elegant xpath expression I wanted to use working so there's an ugly string comparison going on in the loop, and 2) it isn't super-robust in terms of error handling)