Writing
Thursday 17 April 2003
Byliner RSS feeds
At last, I’ve got round to implementing RSS feeds for your favourite web writers on Byliner.
Back when I was wondering whether to dump Byliner one of the things that swung me back towards keeping it was the idea of producing RSS feeds for each users’ stories. RSS wasn’t used much when I originally wrote Byliner but when Yoz and then Ben Hammersley suggested RSS feeds I became enthusiastic about the site again.
So, at last, you can now read stories by your writers in your favourite news reader, not just on the website or via email. The feeds are all a bit “beta”, and there’s plenty of room for improvement, so I’d appreciate any thoughts.
When thinking about writing the code, one of the issues I was pleased to resolve was some form of caching. Given that some peoples’ readers check for new stories frequently, I didn’t want to run a database query and generate a new RSS file on every request. But I also didn’t want to go to the other extreme and periodically generate RSS files for all the users, as most would never be used. Matt and I thought about ways of detecting and redirecting 404s, but he is clever and came up with a better, and rather technical, solution…
This requires that mod_rewrite is enabled on the Apache server, which I think is fairly standard. In the site’s /rss/ directory I have a .htaccess file like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([0-9]{1,6})\.rdf /cgi-bin/rss.cgi?userid=$1
The second line looks to see if the requested file (eg, /rss/1234.rdf) exists. If it doesn’t the third line matches the user ID (the “1234”) and passes it to a perl script that generates the RSS file. Next time 1234.rdf is requested it exists, and so the static file is served. Periodically another perl script deletes all the RSS files from the /rss/ directory so they stay fresh. Just right.
Commenting is disabled on posts once they’re 30 days old.