#!/usr/bin/perl -w $usage = "do_html list_file list_file has Main and Sub topics, and is in the format: ,, Note there is no extention because it uses the name for .jpg and .html output Our file looks like: m,Argus Home,in_index.html,index m,Philosophy,in_philosophy.html,philosophy m,Specifications,in_specs.html,specs m,Pictures,in_images.html,images m,Current Events,in_cwork.html,cwork m,People,in_people.html,people m,Links,in_links.html,links First it will convert in_index.html into index.html with the title and menu stuff in there. In in_index.html, you need to have and tags ON LINES OF THEIR OWN and do_html.pl will insert the title picture. Same goes for and tags for the menu. Whatever is in between these tags gets replaced by the real menu, so you can put some template title and menu in there when you're designing the pages. Right now it's very hard coded to the menus and buttons that we're using for Argus, but that can change in time. "; if($#ARGV < 0 || $ARGV[0] eq "-h" || $ARGV[0] eq "--help" ) { print $usage; exit; } $file = $ARGV[0]; print "Converting $file to unix format\n"; system("dos2unix $file"); print "Processing file $file\n"; open(LIST_FILE, $file) or die "Cannot open $file"; @list_lines = ; # Generate hash that says who everyone's parent is foreach $list_line (@list_lines) { ($level, $name, $type, $directory, $file) = split(/\t/, $list_line); if (!$file) { print "$name has an invalid format.\n"; exit(); } chomp($file); if ($directory eq "" or $type =~ m/ALONE/ or $type =~ m/EMAIL/) { $directory = "."; } $out_file = $directory . "/" . $file . ".html"; $parents_array[$level] = $out_file; # Set yourself to be the parent at your level if ($level != 1) { $parent_hash{$out_file} = $parents_array[$level-1]; } else { # If you're level 1, you are your own parent. $parent_hash{$out_file} = $out_file; } } foreach $list_line (@list_lines) { ($cur_level, $cur_name, $cur_type, $cur_directory, $cur_file) = split(/\t/, $list_line); chomp($cur_file); if ( $cur_type =~ m/NORM/ ) { if ($cur_directory eq "") { $cur_directory = "."; } if ( $cur_directory eq "." ) { $main_directory = "."; } elsif ( $cur_directory =~ m/\// ) { $main_directory = "../.."; } else { $main_directory = ".."; } $cur_in_file = $cur_directory . "/in_" . $cur_file . ".html"; $cur_out_file = $cur_directory . "/" . $cur_file . ".html"; open(IN_HTML, $cur_in_file) or die "Cannot open $cur_in_file file"; open(OUT_HTML, ">$cur_out_file") or die "Cannot open $cur_out_file file for writing"; @cur_in_html_lines = ; $preamble = " $cur_name - Jason Gallicchio
"; $corner = "
"; $top = "

$cur_name -- Jason Gallicchio

"; $footer = "
© Jason Gallicchio 1997-2008       jason\@physics.harvard.edu
See Also:       SVGKit       Apple Picking Boston       Christmas Lights Boston       Christmas Tree Map
"; $postamble = "
"; $mode = 0; # 0=Wait for 1=Print 2=Wait to EOF foreach $cur_in_html_line (@cur_in_html_lines) { if ($mode == 0 && $cur_in_html_line =~ m//) { $mode = 1; print "In Body of $cur_in_file..."; #154 width print OUT_HTML $preamble; print OUT_HTML $corner; print OUT_HTML $top; &menu(); print OUT_HTML "
\n"; } elsif ($mode == 1 && $cur_in_html_line =~ m/<\/body>/) { $mode = 2; print " ...out of body of $cur_in_file\n"; print OUT_HTML "\n
"; print OUT_HTML $footer; print OUT_HTML $postamble; } elsif ($mode == 1 && !($cur_in_html_line =~ m/<\/body>/)) { print OUT_HTML $cur_in_html_line; } } } } system("chmod -R a+rX *"); sub menu{ print OUT_HTML "\n
\n"; $prev_but_level = 0; foreach $but_list_line (@list_lines) { ($but_level, $but_name, $but_type, $but_directory, $but_file) = split(/\t/, $but_list_line); chomp($but_file); #Determine what this button should link to if ( $but_type =~ m/ALONE/ ) { $but_link = $but_directory; } elsif ( $but_type =~ m/EMAIL/ ) { $but_link = "mailto:$but_directory"; } elsif ( $cur_directory eq "." ) { $but_link = $but_directory . "/" . $but_file . ".html"; } else { $but_link = $main_directory . "/" . $but_directory . "/" . $but_file . ".html"; } #Calculate what we have to look up in the parent hash table if ($but_directory eq "" or $but_type =~ m/EMAIL/ or $but_type =~ m/ALONE/) { $but_directory = "."; } $but_out_file = $but_directory . "/" . $but_file . ".html"; # For table lookup, not for linking $but_parents_array[$but_level] = $but_out_file; # Set yourself to be the parent at your level if ( $parent_hash{$cur_out_file} eq $parent_hash{$but_out_file} or $but_out_file eq $parent_hash{$cur_out_file} or $cur_out_file eq $parent_hash{$but_out_file} or $parent_hash{$but_out_file} eq $parent_hash{$parent_hash{$cur_out_file}} or $but_level == 1) { if ( $prev_but_level == $but_level) { print OUT_HTML "\n"; } while ($prev_but_level < $but_level) { print OUT_HTML "\n
    \n"; $prev_but_level++; } while ($prev_but_level > $but_level) { print OUT_HTML "\n
\n"; $prev_but_level--; } print OUT_HTML "
  • $but_name"; $prev_but_level = $but_level; } } # Finish up by ending open tags. if ( $prev_but_level == 1) { print OUT_HTML "
  • \n"; } while ($prev_but_level > 1) { print OUT_HTML "\n \n"; $prev_but_level--; } print OUT_HTML "\n"; print OUT_HTML "
    \n\n"; }