#!/usr/bin/perl -w

use strict;
use CGI;
#use CGI::Carp qw(fatalsToBrowser);
use XML::RSS;

use lib 'lib';
use Sporkstorms::Post;
use Sporkstorms::Util qw(htmlify);

use constant POSTS_PER_PAGE => 20;

my $q = CGI->new;

main();
sub main
{
	my @posts = Sporkstorms::Post->retrieve_last_x(POSTS_PER_PAGE);
	my $rss = XML::RSS->new(version => '1.0');
	$rss->channel(
		title => 'sporkstorms.org blog',
		'link' => 'http://sporkstorms.org/blog.html',
		description => 'tethered to a burning sphere',
	);
	for (@posts) {
		$rss->add_item(
			title => htmlify($_->title),
			'link' => 'http://sporkstorms.org/blog' . $_->id . '.html',
			description => htmlify($_->body),
		);
	}
	print $q->header(-type => 'application/rss+xml', -charset => 'utf-8');
	print $rss->as_string;
}

