#!/usr/bin/perl -w
# Blosxom Plugin: archives
# Author: Brian Akins (bakins@web.turner.com)
# Version: 0+2i
# Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom

package archives;

# --- Configurable Variables ---
# Do you want the list sorted in reverse chronological order?
my $reversechron=1;

# Customize your month names here if you want to.
my @monthname=('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul',
               'aug', 'sep', 'oct', 'nov', 'dec');
# ------------------------------

$archives = '';

sub start {
    return 1;
}

sub filter {
    my ($pkg, $files) = @_;
    my %archive;
    
    foreach (keys %{$files}) {
	    my @date = localtime($files->{$_});
        my $month = $date[4];
    	my $year  = $date[5] + 1900;

        $archive{$year}{'count'}++;
        $archive{$year}{$month}{'count'}++;
    }
    
    my $results = qq{<ul class="archives">};

    foreach my $year(sort {$reversechron?$b<=>$a:$a<=>$b} keys(%archive)) {
        $results .= qq{<li><a href="$blosxom::url/$year/">$year };
        $results .= qq{($archive{$year}{'count'})</a><ul>};
        delete $archive{$year}{'count'};
        
        foreach my $month(sort {$reversechron?$b<=>$a:$a<=>$b} 
                                      keys(%{$archive{$year}})) {
            my $mnum = sprintf("%02d", $month+1);
            $results .= qq{<li><a href="$blosxom::url/$year/$mnum/index.$blosxom::flavour">};
            $results .= qq{: $monthname[$month] };
            $results .= qq{($archive{$year}{$month}{'count'})</a></li>};
        }
        
        $results .= "</ul></li>";
                          
    }

    $results .= "</ul>";
        
    $archives = $results;
}

1;
