August 02, 2002

Blogroll using RSS feeds for MovableType

Weblogs | XSLT

I've finally managed to integrate my simple Blogroll engine into the MT system. The sytem is a combination of XML/XSLT, MT regeneration of HTML pages and crontab.

This is essentially composed of two components.

The first component is an XML file which describes what are the RSS feeds you're interested in. In this file you specify the location of the feed, and optionally you can give a simple name to it. This name is used in the generated HTML as the title for the news, in case the RSS feed doesn't specify a name in it (like Slashdot for example).

Here is a simple XML feed document:

<rssfeed> 
  <user>Ovidiu Predescu</user> 
  <title>Ovidiu Predescu's news stories</title> 
  <stylesheet>rssfeeds.css</stylesheet> 
 
  <subscriptions> 
    <rss name="Ovidiu Predescu" href="http://www.webweavertech.com/ovidiu/weblog/index.rdf" />
    <rss name="Slashdot" href="http://slashdot.org/slashdot.xml"/> 
    <rss name="James Strachan" href="http://james.weblogger.com/xml/rss.xml"/> 
    <rss name="Sam Ruby" href="http://radio.weblogs.com/0101679/rss.xml"/> 
    <rss name="Matthew Langham" href="http://radio.weblogs.com/0103021/rss.xml"/> 
  </subscriptions> 
</rssfeed> 

The XSLT stylesheet then takes this document and translates into HTML. The stylesheet knows how to handle RSS 0.91 and RSS 0.92, which are the formats used by Radio, RSS 1.0 (preferred by Radio), and Backslash, which is used by Slashdot.

I defined the generated HTML file as template in MT, which I called RSSFeedNews. In my new templates for MT 2.21, I include this template in the appropriate place so it can appear in the generated HTML.

I want to automatically retrieve the news, create the HTML fragment to be inserted in each page, and then regenerate all the pages with the fresh news. For this task, I've dug into MT to see how to do it. The documentation was quite clear on what needs to be done, but I encountered some problems. Below is the script which seems to work fine now.

#!/usr/bin/perl -w 
use strict; 
use lib '/path/to/mt/lib'; 
use lib '/path/to/mt/extlib'; 
use MT; 
my $mt = MT->new( Config => '/path/to/mt/mt.cfg', 
                  Directory => '/path/to/mt'); 
 
my $result = $mt->rebuild( 
                          BlogID => 1, 
                          EntryCallback => sub { print " => ", $_[0]->title, "\n" } 
                          ); 
 
print "Done.\n"; 

The POD documentation for lib/MT.pm does not mention that the Directory parameter in new is required. I found that after few hours of poking around.

To run the translation you need to have an XSLT processor. I use Saxon, a compliant and very fast XSLT processor written in Java. With Saxon you run the translation like this:

java -jar saxon.jar subscriptions.xml rss2html-standalone.xsl

The rss2html-standalone.xsl XSLT stylesheet will generate a complete HTML, you'll need to customize it for inclusion in another HTML document. This is usually done by simply removing the unnecessary HTML tags from the rssfeed template.

I've put all the necessary code you need to run in this directory.

Posted by ovidiu at August 02, 2002 01:18 AM |
 
Copyright © 2002-2016 Ovidiu Predescu.