#!/usr/bin/perl -w

# If this small chunk of code wants a license, be it the GPL.
# So this is FREE SOFTWARE, see http://www.gnu.org/
# Copyleft (c) 2003 Jean Zundel

# Basically we take html bodies and assemble them with common
# headers, substituting/inserting various stuff along the process.
# Comments on the same line as an IMG tag wreak havoc. No, I won't fix it.

use strict;

my $line;

my $title = <>;                # 1st line contains the title in html comments
$title =~ s/<!-- (.*) -->/$1/;


open (HEAD, "<head.html") or die "head.html: $!\n";
open (TAIL, "<tail.html") or die "tail.html: $!\n";
while (<HEAD>) {
    s/(<title>)/$1Rickenbacker Amplifiers - $title/i;
    print;
}
close HEAD;

print "\n<!-- Generated by site.pl - edit only the pre-XXX.html -->\n\n";

print "<hr><center><h1>$title</h1></center><hr>\n\n";

while (<>) {
    s/(<h.>)/<center>$1/io;                # H1 H2 H3 tags are centered
    s/(<\/h.>)/$1<\/center>/io;

    my $line = $_;

    if (m/<img/io) {
    />/ or                                 # 2-line img tag (no more...)
        $line .= <>;                       # Append next line
                                           # and add a tooltip
    $line =~ s/(.*alt=)("[^\"]*")([^>]*)>(.*)/$1$2$3 title=$2>$4/;
                                           # and decorate wildly
    $line = "<center><table border=\"2\"><tr><td>\n"
        . $line 
        . "</td></tr></table></center>\n";
    }
    print $line;
    
}

while (<TAIL>) {
    print;
}
close TAIL;
