2006-08-04.03:07:00.archives

I added a monthly archive and a dynamic sidebar thingy which generates links to it, as well as limited the front page to the last 3 newest posts. The sidebar is generated by using
$c->forward(qw/ archives /);
The responsible code looks like this:
sub archives : Private {
    my ($self, $c) = @_;
    my $m = $c->model('Posts');
    my @posts = $m->list;
    my %months;
    foreach (@posts) {
        my ($year, $month, $bits) = split /-/, $_;
        $months{$year.'-'.$month}++;
    }
    $c->stash->{months} = [keys %months];
}
I kinda cheaped out a bit and used the foreach loop, but the list of posts for the month generated by this code is I think a bit cleaner looking.
sub month : Path('/month') : Args(1) {
    my ($self, $c, $month) = @_;
    ($month) = $month =~ /^(\d{4}\-\d{2})$/;
    $c->detach(qw/ frontpage /) unless defined $month;
    my $m = $c->model('Posts');
    $c->stash->{posts} = [grep /$month/, $m->list];
    $c->forward(qw/ archives /);
    $c->stash->{template} = 'month.tt2';
}
Finally I limited the number of posts on the front page by changing this line:
my %posts = map { $_ => scalar $m->slurp($_) } $m->list;
To this line
my %posts = map { $_ => scalar $m->slurp($_) } (reverse $m->list)[0 .. 2];
I think I'll look at doing an RSS feed of some sort in the next couple of days.