#!/usr/bin/perl
use strict;
use XML::RSS::SimpleGen;
use File::Slurp;
use Mojo::DOM58; # works with perl 5.10
my $url = q<http://superkuh.com/blog/recent31337.html>;
my $baseurl = q<http://www.superkuh.com>;

print "starting...\n";

rss_new( $url, "superkuh", "all blog posts ever" );
rss_language( 'en' );
rss_webmaster( 'rss@superkuh.com' );
rss_daily();

get_url( $url );

my @titles;
my @urls;

my $html = $_;
my $dom = Mojo::DOM58->new($html);
# <xenu> btw, note that 'say $_->preceding('a')->first->text' will die if there's no preceding <a>, if you need to handle it more gracefully, you can use a callback
# <xenu> $_->preceding('a')->first(sub { say $_->text });
# <xenu> "say $->text" will be executed only if the preceding <a> is found
$dom->find('li > a:nth-of-type(2)')->each(sub {
	#print $_->{href};
	#print $_->preceding('a')->first->text;

	my $fileurl = $_->{href};
	my $titletext = $_->preceding('a')->first->text;

	my $file = "/home/superkuh/www$fileurl";
	my $fulltext = read_file( $file ) ;
	#print "file: $file\n";
	#print "fulltext: $fulltext";
	$fulltext =~ m/<div.+?>/;
	$fulltext = $';
	$fulltext =~ m/<\/div>/;
	$fulltext = $`;
	#print "fulltext: $fulltext";

	rss_item("$baseurl$fileurl", $titletext, $fulltext);

});

#rss_item("$baseurl$4", $3, $5);
die "No items in this content?! {{\n$_\n}}\nAborting"
 unless rss_item_count();

rss_save( '/home/superkuh/www/rss-all.xml', 45 );
exit;
