Roan Horning
e31c4a2208
Added a function to facilitate looping through a list of pages to be generated. Currently hard coded the generation of the contact page based on the site.cfg file.
90 lines
1.6 KiB
Perl
Executable File
90 lines
1.6 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
=head1 NAME
|
|
|
|
siteGenerator - HPR Site Generator
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
siteGenerator [OPTION]... PAGE...
|
|
|
|
-v, --verbose use verbose mode
|
|
--help print this help message
|
|
|
|
Where I<PAGE> is a file name of a web page.
|
|
|
|
Examples:
|
|
|
|
Generate two specific pages:
|
|
siteGenerator index about
|
|
|
|
Generate the whole site:
|
|
siteGenerator ALL
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This is a site generator based upon the Perl Templates Toolkit.
|
|
|
|
=head1 AUTHOR
|
|
|
|
Roan Horning <roan.horning@no-spam.gmail.com>
|
|
|
|
=cut
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Getopt::Long qw(:config auto_help);
|
|
use Pod::Usage;
|
|
use Config::Std;
|
|
use Template;
|
|
|
|
exit main();
|
|
|
|
sub main {
|
|
|
|
# Argument parsing
|
|
my $verbose;
|
|
GetOptions(
|
|
'verbose' => \$verbose,
|
|
) or pod2usage(1);
|
|
pod2usage(1) unless @ARGV;
|
|
my (@pages) = @ARGV;
|
|
|
|
# Load config file
|
|
read_config "site.cfg" => my %config;
|
|
|
|
my $tt = get_template_html();
|
|
generate_page($tt, $config{contact}{navigation}, $config{contact}{content});
|
|
|
|
return 0;
|
|
}
|
|
|
|
sub get_template_html {
|
|
|
|
# For an HTML based Template file, define the
|
|
# template start and end tags to also function as
|
|
# HTML comments to make the template file valid HTML.
|
|
#
|
|
return Template->new({
|
|
INCLUDE_PATH => './templates',
|
|
EVAL_PERL => 1,
|
|
START_TAG => '<!--%',
|
|
END_TAG => '%-->',
|
|
}) || die $Template::ERROR, "\n";
|
|
|
|
}
|
|
|
|
sub generate_page ($tt, $navigation, $content) {
|
|
my ($tt, $navigation, $content) = @_;
|
|
my $tt_vars = {
|
|
navigation => $navigation,
|
|
content => $content
|
|
};
|
|
|
|
$tt->process('page.tpl.html', $tt_vars)
|
|
|| die $tt->error(), "\n";
|
|
|
|
}
|
|
|