#!/usr/bin/perl -w -l use strict; use FileHandle; use Time::localtime; use File::stat; use Time::Local; use POSIX qw(strftime); use CGI qw/:standard :netscape/; my $datadir = 'blosxom'; my $fh = new FileHandle; # Take a gander at HTTP's PATH_INFO for optional blog name, archive yr/mo/da my @pi = split m{/}, path_info(); shift @pi; my $year = shift(@pi) || 1900+localtime()->year; my $mon = shift(@pi) || 1+localtime()->mon; #compute the range of this month: start(inclusive)..fin(exclusive) my $start = timelocal(0,0,0, 1, $mon-1, $year); my $fin = $mon<11 ? timelocal(0,0,0, 1, $mon, $year) : timelocal(0,0,0, 1,0,$year+1); # Get the names/values of the previous, current, and next months sub clt{CORE::localtime(shift)} my $month = strftime("%B", clt($start)); my ($pmo, $pmonth, $pyear) = split(/ /, strftime "%m %B %Y", clt($start-1)); my ($nmo, $nmonth, $nyear) = split(/ /, strftime "%m %B %Y", clt($fin)); # Get a list of files, map by mod time, filter by range, sort by date my @files = glob("$datadir/*.txt"); my %dir = map {stat($_)->mtime => $_} @files; my %files = map {$_ => $dir{$_}} grep {$_>=$start and $_<$fin} keys %dir; my @times = sort keys %files; # Write headers print "Content-type: text/html\n\n"; $fh->open("$datadir/head.blot"); my $head = join("",<$fh>); $head =~ s/(\$\w+)/$1 . "||''"/gee; print $head; # Send in the blogs my $mark = $start - localtime($start)->wday*24*60*60; push @times, timelocal(0,0,0,1,1,$year+1); my $i = 0; while ($mark < $fin) { print ""; for (1,2,3,4,5,6,7) { # Date $i++; print ""; my $page = strftime "/blog/%Y/%m/%d", clt($mark); print strftime "%d", clt($mark) if localtime($mark)->mon == $mon-1; # Titles my $first=1; $mark += 24*60*60; while ($times[0] < $mark) { print ($first? ""); print ""; } print ""; } $fh->open("$datadir/foot.blot"); my $foot = join("",<$fh>); $foot =~ s/(\$\w+)/$1 . "||''"/gee; print $foot;