#!/usr/bin/perl -w

use strict;

my ($name)=@ARGV;

my %dirs=();

opendir LIST,"../html/archives/$name/";
foreach my $dir (readdir LIST) {
  if($dir=~/^(\d+)-(\w+)$/) {
    $dirs{$1}->{$2}=1;
  }
}
closedir LIST;

open HTML,">../html/archives/$name/index.html";

print HTML << 'HEAD';
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
HEAD

print HTML "<title>$name archives</title>\n";

print HTML << 'MIDDLE';
</head>
<body>
MIDDLE

print HTML "<h1>abc-$name archives</h1>\n<hr/><table>\n";

foreach my $year (sort keys %dirs) {
  print HTML "<tr><td>$year:</td>";
  foreach my $month ('Jan','Feb','Mar','Apr',
		     'May','Jun','Jul','Aug',
		     'Sep','Oct','Nov','Dec') {
    if(exists $dirs{$year}->{$month}) {
      print HTML qq{<td>[<a href="$year-$month/">$month</a>]</td>};
    } else {
      print HTML "<td></td>";
    }
  }
  print HTML "</tr>\n";
}

print HTML << 'TAIL';
</table>
<hr/>
</body>
</html>
TAIL

close HTML;
