#!/usr/bin/perl -w

=pod

=NAME

generate_web_pages.pl - generate the web pages for the install site

=SYNOPSIS

Yeah, it does that.

Basically, there's a few comments in shell.hemp that we replace with
    what we really want in the files. Pretty simple.

The point of this is to look like the main site.

=cut

# This is the list of pages to generate: Change this to
# add/subtract/etc. pages. Index is done seperately.
# Title, source

my @pages = (
              ['Fedora 8 Install', 'F8_install'], 
              ['Fedora 7 Install', 'F7_install'],
              ['Fedora Core 6 Install', 'FC6_install'], 
	      ['Fedora Core 5 Install', 'FC5_install'],
#             ['Fedora Core 4 Install', 'FC4_install'],
#             ['Fedora Core 3 Install', 'FC3_install'],
#	      ['Fedora Install', 'fedora_install'],
#	      ['Red Hat 7.3 Install', 'rh73'],
              ['Red Hat Enterprise Linux 5 Install','RHEL5_install'],
              ['Red Hat Enterprise Linux 4 Install','RHEL4_install'],
              ['SuSE Linux 10.2 Install', 'suse10.2_install'],
              ['SuSE Linux 10.1 Install', 'suse10.1_install'],
              ['SuSE Linux Professional 9.3 Install', 'suse9.3_install'],
#              ['SuSE Linux Professional 9.2 Install', 'suse9.2_install'],
              ['SuSE Linux Enterprise Server 10 Install', 'sles10_install'],
              ['SuSE Linux Enterprise Server 9 Install', 'sles9_install'],
#	      ['Manual Install from Tarballs', 'manual_install'],
	      ['Upgrading from Previous LON-CAPA install', 'upgrade'],
	      ['LON-CAPA License (Gnu Public License)', 'license']
	      );

my @testing_pages = ( 
		      );
my @other_pages = ( 
		    ['Developer Information', 'dev'],
		    ['Configuration Information', 'config'],
		    );

open SHELL, '<', "shell.html";
my $shell = join '', <SHELL>;
$shell =~ s/\r/\n/g;

# Call with: The title, breadcrumb, and content
sub replaceText {
    my ($title, $links, $breadcrumb, $content) = @_;

    my $page = $shell;
    $page =~ s/\<!-- *title *--\>/$title/g;
    $page =~ s/\<!-- *links *--\>/$links/g;
    $page =~ s/\<!-- *breadcrumb *--\>/$breadcrumb/g;
    $page =~ s/\<!-- *content *--\>/$content/g;

    return $page;
}

# Do the index page

open INDEX, '>', "index.html";
my $content = <<PRELUDE; 

<p>LON-CAPA is based upon a lot of Open Source modules, so it's
important to have the right environment on your computer. This is most
easily done by installing on a dedicated machine while installing the
operating system.</p>

<p>The configuring of LON-CAPA is part of the install process of the
software. However, In case something needs to be altered, or isn't
working, here is some <a href="config.html">information on configuring
LON-CAPA</a>.</p>

<hr />
PRELUDE

$content .= "<ul>\n";
for (@pages) {
    $content .= "<li><a href='$_->[1].html'>$_->[0]</a></li>\n";
}

$content .= "</ul>\n";

my $testing_content = '';
if (@testing_pages) {
    $testing_content .= "<hr/><p>Installation on the following systems requires the use of a testing release of LON-CAPA.</p>\n";
    $testing_content .= "<ul>\n";
    for (@testing_pages) {
	$testing_content .= "<li><a href='$_->[1].html'>$_->[0]</a></li>\n";
    }
    $testing_content .= "</ul>\n";
}


$content .= <<"POSTLUDE";
<hr />
<a name="download" />
<h3>Downloading LON-CAPA</h3>

<p>
<b>Current Production Release is Version LATESTVERSION.
This version was released on LATESTDATE.</b>
</p>
<p>
You can download the <b>most current production version of LON-CAPA</b> at
<a href="http://install.lon-capa.org/versions/loncapa-current.tar.gz">
http://install.lon-capa.org/versions/loncapa-current.tar.gz</a>
(version LATESTVERSION).
</p>
TESTINGRELEASE_START
<p>
<b>Current Testing Release is Version LATESTTESTINGVERSION.
This version was released on LATESTTESTINGDATE.</b>
</p>
<p>
You can download the <b>testing version of the upcoming LON-CAPA</b> at
<a href="http://install.lon-capa.org/versions/loncapa-testing.tar.gz">
http://install.lon-capa.org/versions/loncapa-testing.tar.gz</a>
(version LATESTTESTINGVERSION).
</p>
$testing_content
TESTINGRELEASE_END

<hr />
POSTLUDE

open(RELEASE, '<', "release.frag");
$content .= join('',<RELEASE>);
close(RELEASE);

$content .= "<ul>\n";
for (@other_pages) {
    $content .= "<li><a href='$_->[1].html'>$_->[0]</a></li>\n";
}

$content .= "</ul>\n";

$links='<link rel="alternate" type="application/rss+xml" title="CVS RSS" href="loncapa.rss" />';

my $index = replaceText("Install LON-CAPA", $links, "Install LON-CAPA",
			$content);

print INDEX $index;
close INDEX;

# Build the pages
for (@pages,@other_pages,@testing_pages) {
    my ($title, $source) = @$_;

    # read in content
    open SOURCE, '<', $source.'.frag';
    $content = join '', <SOURCE>;
    close SOURCE;

    $content = replaceText($title, '', '<a href="/">Install LON-CAPA</a> &gt; ' . $title,
			   $content);
    open DEST, '>', $source.'.html';
    print DEST $content;
    close DEST;
}
