#!/usr/bin/perl # makeswal.pl v 0.1 # makes an issue of swallow # input files go in $indir/[issue_number] # - input files are template.html # - use {{text}}, {{contents}} and {{[all keys in %issue]}} in template # - add $src to keys named in %regulars or %features for other input files # output files appear in $outdir/[issue_number] # - output files add $xtn to keys named in %regulars or %features # - handle images yourself use strict; my %regulars = ( 'toon' => 'The Internet Is Something But We Don\'t Know What', 'pedant' => 'A <pedant> writes </pedant>', 'index' => 'Bad Editor', 'links' => 'o-o-o', 'aq' => 'AQ' ); my %features = ( 'durlab' => 'Two Poems By Durlab Singh', 'swallow' => 'Set Up A Site Like Swallow', 'heyoka' => 'heyoka on pasta', ); my %issue = ( 'number' => 13, 'issue_string' => 'rather strange litmag', 'date' => '4/11/00', ); my $outdir = "/home/waz/www/easynet/swallow"; # location of output files my $xtn = ".html"; # extension of output files my $indir = "/home/waz/www/easynet/swallow/dev"; # location of input files my $src = ".txt"; # extension of input files my $contents; my $template = "template.html"; my $contstemp = "<P>{{item}}\n<HR WIDTH=\"75%\">\n"; my $verbose = 1; # make contents $contents = make_contents(); # make each page. for (keys %regulars, keys %features) { make_page($_); } # done exit 0; # make_contents # parse %regulars, %features and $contstemp # return string for $contents sub make_contents { my $item; my $tmp; my $cts; my @array = (keys %regulars, keys %features); # sort the contents by length of assoc. string, decreasing @array = reverse sort { length ($regulars{$a} || $features{$a}) <=> length ($regulars{$b} || $features{$b}) } @array; # step through and do the do for(@array) { $item = "<A HREF=\"$_$xtn\">".($regulars{$_} || $features{$_})."</A>"; $tmp = $contstemp; $tmp =~ s/{{ITEM}}/$item/s; $cts .= $tmp; } return $cts; } # make_page # actually makes a page sub make_page { my $page = shift; my $title = $regulars{$page} || $features{$page}; # get the template and the source text my $cts = open_file("$indir/$issue{'number'}/$template"); my $txt = open_file("$indir/$issue{'number'}/$page$src"); # sub in the text $cts =~ s/{{text}}/$txt/s; # sub in the contents $cts=~ s/{{contents}}/$contents/s; # sub in everything else for(keys %issue) { $cts =~ s/{{$_}}/$issue{$_}/sig; } # write the file write_file("$outdir/$issue{'number'}/$page$xtn", $cts); } # open_file # opens $file and return $contents sub open_file { my $contents; my $file = shift; print "Reading $file\n" if $verbose; open INFILE, $file or die "Can't open $file - $!\n"; while (<INFILE>) { $contents.=$_; } close INFILE or die "Can't close $file - $!\n"; return $contents; } # write_file # writes $contents to $path or dies sub write_file { my $path = shift; my $contents = shift; print "Writing $path\n" if $verbose; open OUTFILE, ">$path" or die "Can't open $path for writing - $!\n"; print OUTFILE $contents; close OUTFILE or die "Can't close $path - $!\n"; print "Wrote $path ok\n" if $verbose; }
rather strange litmag
heyoka on pasta and other things i forgot or lost
The Internet Is Something But We Don't Know What
An Important Election-Day Message by rageboy