#!/usr/bin/perl use Template; use File::Find; use strict; my $blog = shift; my @Month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my (%year, $yr, $mo, @posts); find( sub { next unless /\.txt$/o; ($yr, $mo) = (localtime((stat($_))[9]))[5, 4]; $year{$yr}[$mo]++; }, $blog ); for $yr (reverse sort keys %year) { my $n = ($yr == (localtime)[5] ? (localtime)[4] : 11); push @posts, [ $yr + 1900, int($n / 4) + 1, map([$Month[$_], $year{$yr}[$_]], (0 .. $n)) ]; } my $tmpl = join "", ; my $tt2 = Template->new(); $tt2->process( \$tmpl, { posts => \@posts } ) || die $tt2->error(), "\n"; __DATA__ [% FOREACH year IN posts %] [% date = year.shift %] [% span = year.shift %]
[% FOREACH month IN year %] [% IF month.1 > 0 %] [% ELSE %] [% END %] [% IF loop.index % 4 == 3 %] [% END %] [% END %]
[[% date %]][% month.0 %][% month.0 %]
[% END %]