#!/usr/bin/perl -wT
use lib ".";
use Kerryandjane;
use strict;
my %sections = ();
print "Content-type: text/xml\n\n";
print <<'EOF';
Kerry and Jane's News
Tedious and rarely-updated news from Kerry and Jane.
http://www.kerryandjane.com
EOF
# first get a list of valid sections
open (LIST, "<", "../data/sections.dat") or die ("Failed to open section list: $!");
while () {
next if /^\s*#/;
if (/^(.*?),(.*)$/) {
$sections {$1} = $2;
}
}
close LIST;
my %files = ();
my $date = "";
foreach my $section (sort keys %sections) {
while (<../data/$section/news/*xml>) {
if (-r) {
my $filename = $_;
$date = get_date ($_);
if ($date) {
if ($files {"$date"}) {
my $temp_date = $date;
for (my $count = 1; $files {"$temp_date"}; $count++) {
$temp_date = sprintf ("%s-%02d", $date, $count);
}
$date = $temp_date;
}
$files {"$date"} = $filename;
}
}
}
}
my $last_file = (keys (%files) < 5 ? keys (%files) - 1 : 4);
foreach ((reverse sort keys %files) [0..$last_file]) {
parse ($files {$_}, "ref");
}
print << "EOF";
Kerry and Jane's Page$Kerryandjane::img_loc/kerryandjane88x31.gif
http://www.kerryandjane.com
EOF
foreach ((reverse sort keys %files) [0..$last_file]) {
parse ($files {$_}, "item");
}
print "\n";
sub get_date {
my ($filename) = @_;
my $year = 0;
my $month = 0;
my $date = 0;
if (-r $filename) {
local $/;
open (ARTICLE, "<", "$filename") or return "00000000";
my $contents = ;
close ARTICLE;
if ($contents =~ m|;
close ARTICLE;
if ($contents =~ m||is) {
$title = $1;
}
if ($contents =~ m|\n";
} else {
$contents =~ m|(.*?)|is;
$body = $1;
# only show the first paragraph
$body =~ s/