#!/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.html 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 = ( 
#	      ['Red Hat 7.3 Install', 'rh73'],
	      ['Fedora Install', 'fedora_install'],
              ['Fedora Core 3 Install', 'FC3_install'],
              ['Fedora Core 4 Install', 'FC4_install'],
	      ['Manual Install from Tarballs', 'manual_install'],
	      ['Upgrading from Previous LON-CAPA install', 'upgrade'],
	      ['Post-installation Configuration', 'config'],
	      ['LON-CAPA License (Gnu Public License)', 'license']
	      );

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

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

    my $page = $shell;
    $page =~ s/\<!-- *title *--\>/$title/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. Since it will frequently 
be the case that LON-CAPA will be going onto a dedicated machine, we've 
included instructions for installing LON-CAPA concurrently with new
installations of some of the popular Linux distributions.</p>

<p>A tarball installation is also available for those who wish to 
install on other distributions. Currently, Apache 1.x is required;
LON-CAPA does not yet run on 2.0.</p>

<p>For all distributions, please see how to 
<a href="config.html">configure the server after installation</a>.</p>
<hr />
PRELUDE

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

$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>
TESTINGRELEASE_END
<p>
The <b>development release of LON-CAPA</b> is at:
<a href="http://install.lon-capa.org/versions/loncapa-unstable.tar.gz">
http://install.lon-capa.org/versions/loncapa-unstable.tar.gz</a>.
</p>
<p>
To view the code development history of LON-CAPA, you can access a <a
href="http://zaphod.lite.msu.edu/cgi-bin/cvsweb.cgi/">web version</a>
of our CVS respository. Otherwise, please contact Helen (<a
href="mailto:helen@lon-capa.org"> helen@lon-capa.org</a>) to request a
CVS USERNAME.
</p>
<p>
The initial CVS commands would be:
</p>
<blockquote>
<table bgcolor="#aaaaaa" border="1">
<tr><td>
<pre>
export CVSROOT=:pserver:USERNAME@zaphod.lite.msu.edu:/home/cvs 
cvs login 
cvs co loncapa
</pre>
</td></tr></table>
</blockquote>
<p>
For more information on using CVS, please visit
<a href="http://www.cvshome.org/">http://www.cvshome.org/</a>
or read <tt>loncom/build/readme.html</tt> after downloading
the current version of LON-CAPA as described above.
</p>

POSTLUDE

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

print INDEX $index;
close INDEX;

# Build the pages
for (@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;
}
