#!/usr/local/bin/perl -wT ######### # author: rmp for edgrif # # This script was originally written by Roger Pettet for Ed Griffiths. It's purpose # is trawl through all the newsletters in one or more YearNNNN directories and prepare # an index.shtml file for each directory. The index file contains nested lists of links # to the major sections within the newsletter. This makes it a bit easier to just eyeball # the newsletters and see what's in the latest one. # # N.B. We rely on the format of the newsletters being just-so and in particular we rely on # the format of the anchors and headers being: # # The actual header # # The script picks out the text of the anchor flag and the text of the actual header. # # # use strict; my $WEB_PATH = '.'; my $FILE_SUFFIX = 'html'; my $DEFAULT_ANCHOR = 'Top' ; for my $dir (@ARGV) { if(! -d $dir ) { print STDERR qq($dir is not a directory\n); next; } else { ######### # untaint $dir # regexp out any nasty characters here # unfortunately file & directories can have virtually anything in # so we do a naughty, useless untaint: # $dir =~ m/(.*)/s; my $cleandir = $1; my $content = ""; &munge_files(\$content, $cleandir); &print_index(\$content, $cleandir); } } 1; sub munge_files { my ($content_ref, $dir) = @_; my @valid_files = qw(January February March April May June July August September October November December); for my $file_head (@valid_files) { my $file = qq($dir/$file_head.$FILE_SUFFIX); if(! -e qq($file) ) { print STDERR qq($file not found\n); next; } else { eval { open(FIN, $file) || die; }; if($@) { print STDERR qq(Could not open $file\n); next; } ######### # nuke input record separator # my $irs = $/; undef($/); my $file_contents = ; ######### # be nice. reset record separator # $/ = $irs; close(FIN); my (@headers) = $file_contents =~ /.*?<\/h.>/mig; print STDERR qq(Found ), scalar @headers, qq( headers in $file\n); if(scalar @headers > 0) { my $htype = "" ; # we could insert an extra link here to get to the overview in one # go... $$content_ref .= qq(\n

$file_head

\n
); } } } } sub print_index { my($content_ref, $dir) = @_; my $year = $dir; $year =~ s/^.*\/(.*?)$/$1/ig; open(FOUT, ">$dir/index.shtml") || die(qq(Could not open index file)); print FOUT qq(\n) ; # warn user that file is machine generated... print FOUT qq(\n\n) ; print FOUT qq(\n) ; print FOUT qq(\n) ; print FOUT qq(\n\n) ; print FOUT qq( Acedb Newsletters for $year

Acedb Newsletters for $year

\n\n); print FOUT $$content_ref; print FOUT qq(\n\n
\n); print FOUT qq(
acedb\@sanger.ac.uk
\n); print FOUT qq(\n\n\n); close(FOUT); print STDERR qq(Generated index $dir/index.shtml\n); }