#!/usr/bin/perl # generatepages.pl, copyright Casey Muller, let me know if you find it # useful at generatepages(at)null-terminated.com and maybe I can give # you a more up to date version. # third beta version: Mar 1st, 2005 #directory constants $webdir = `pwd`; chomp $webdir; $rootdir = $webdir."/root"; $stagingdir = $webdir."/staging"; $commentdir = $webdir."/comments"; $imgprefix = "http://bigfiles.null-terminated.com:81/digitalcamera/"; $thumbpath = "/visuals/photography/by-date/"; $thumbprefix = "http://null-terminated.com".$thumbpath; #load the html templates require "templates.pl"; use File::Find; find sub { /^\./ && return; if (-d $File::Find::name) { push @{ $dirs{$File::Find::dir} }, $_; $newdir = $stagingdir.substr $File::Find::name, length($rootdir); if (!-d $newdir) { print "making: $newdir\n"; system("mkdir \"$newdir\""); } } }, $rootdir; # open the root directory. HTML files get processed, others assumed copied. find sub { if(/\.html$/) { print "processing $_ in $File::Find::dir\n"; # get just the portable part $dir = substr $File::Find::dir, length($rootdir); # get the comment name ($commentfile = $_) =~ s/\.html$/\.comments/; # open the output file open(OUTPUT, '>', "$stagingdir$dir/$_") || die "can't write $stagingdir$dir/$_"; # split it up @tracedirs = split m%/%, $dir; shift @tracedirs; $host = shift @tracedirs; $url = "http://".$host.".com".substr $File::Find::name, length($rootdir.$host)+1; # write out the html print OUTPUT $pretitle; # supply the title: $title = ""; if($_ ne "index.html") { # interesting html filename? ($stripfile = $_) =~ s/\.html$//; $title .= $stripfile." : "; } if($#tracedirs > -1) { # interesting subdir? $title .= $tracedirs[-1]." : "; } $title .= $host; print OUTPUT $title; #are there any subdirs? if(length @{ dirs{$File::Find::dir}}) { # print them out print OUTPUT $title2menu; #print each subdirectory: foreach(@{ $dirs{$File::Find::dir} }) { if(defined $dirs{"$File::Find::dir/$_"}) { print OUTPUT "
\n";
open(INPUT, "$File::Find::name");
while() {
# duplicated code:
s#$3#g;
s#
$3#g;
if(/^$/) {
print OUTPUT "
"; } print OUTPUT $_; } print OUTPUT "\n
\n"; close INPUT; print OUTPUT $content2comments; # open the comment file if it exists $commentfile = "$commentdir$dir/$commentfile"; if(-r $commentfile) { open(COMMENTS, "$commentfile"); print OUTPUT "Old-school comments:"; while("; close COMMENTS; } print OUTPUT $comments2disqus; print OUTPUT "var disqus_url = '".$url."';\n"; print OUTPUT "var disqus_title = '".$title."';\n"; print OUTPUT "\n"; print OUTPUT ''; print OUTPUT $disqus2tag; print OUTPUT $host; print OUTPUT $posttag; print OUTPUT $ad{$host}; print OUTPUT $adtoend; close OUTPUT; return; } }, $rootdir;) { print OUTPUT "$_"; } print OUPUT "