#!/usr/bin/perl
# processarchives.pl, copyright Casey Muller, let me know if you find
# it useful at processarchives(at)null-terminated.com and maybe I can
# give you a more up to date version.
# fourth beta version: Mar 1st, 2005
# TODO for fifth beta: fix RSS metadata
#directory constants
$webdir = `pwd`;
chomp $webdir;
$caseydir = $webdir."/root/casey0";
#$caseydir = $webdir."/staging/casey0";
$nulltdir = $webdir."/root/null-terminated";
#$nulltdir = $webdir."/staging/null-terminated";
$archivedir = $caseydir."/archive";
$tagdir = $caseydir."/tags/";
$imgprefix = "http://bigfiles.null-terminated.com:81/digitalcamera/";
$thumbpath = "/visuals/photography/by-date/";
$thumbprefix = "http://null-terminated.com".$thumbpath;
# structure: in each directory $archivedir/year/month there are
# ##.entry files which contain the entry for the ##th day. In them,
# the first line is the title, the second line is a timestamp (which
# is added if it doesn't exist), and the rest is stuck in the
# title.html file. Each index.html has links to all sub-titles (for
# now). The most recent 10 go in $webdir.
#load the feed templates
require "feedconstants.pl";
#use XML::RSS;
use POSIX;
#my $rss = new XML::RSS;
#$rss->channel(
# title => $feedtitle,
# link => $feedURL,
# description => $feeddesc,
# dc => {
# rights => "Casey Muller under a Creative Commons license",
# language => "en-us",
# },
# syn => {
# updatePeriod => "daily",
# updateFrequency => "2",
# updateBase => "1980-06-24T08:00-08:00",
# },
# );
$today = strftime "%Y-%m-%dT%H:%M:%SZ", gmtime();
open(RSS, '>', "$caseydir/casey0.rss");
print RSS <$feedtitle$feeddesc$today$feedRSSURLCasey Mulleratomfeed\@nullterminated.com
RSSHEADER
@months = qw(January February March April May June July August September October November December);
@monthnums{@months} = 1..$#months+1;
use File::Find;
# open the archive directory. .entry files get processed as entries
find { preprocess => sub {
# sort by month slice if it's a year dir
my $depth = (substr $File::Find::dir, length($archivedir)) =~ tr[/][];
if($depth == 1) {
sort {$monthnums{$a} <=> $monthnums{$b}} @_;
} else {
# need 2 to appear before 10
sort {$a <=> $b} @_;
}
}, wanted => sub {
if(/(.*)\.entry(\d*)$/) {
print "processing $_ in $File::Find::dir\n";
# get just the archive part
$dir = substr $File::Find::dir, length($archivedir);
$archdir = substr $File::Find::dir, length($caseydir);
# get date from filename and path
$day = $1;
# split it up
@tracedirs = split m%/%, $dir;
shift @tracedirs;
$year = shift @tracedirs;
$month = shift @tracedirs;
$monthnum = sprintf "%02s", $monthnums{$month};
$daynum = sprintf "%02s", $day;
# open it
open(INPUT, "$File::Find::name")
|| die "can't read $File::Find::name";
$title = ;
chomp $title;
$tagline = ;
chomp $tagline;
@tags = split ' ', $tagline;
# what's the relative url?
$url = "$archdir/$title.html";
$url =~ y/ /_/;
# save info to add to rss and index
$indexhtml = "$title