Add write to file functionality to the site-generator
Add preview option to display generated html in standard out. Default output of generated html is now written to a file in the public_html directory with the name of the page with a .html extension.
This commit is contained in:
parent
e9911f99f9
commit
d0443f0a7d
@ -2,12 +2,13 @@
|
||||
|
||||
=head1 NAME
|
||||
|
||||
siteGenerator - HPR Site Generator
|
||||
site-generator - HPR Site Generator
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
siteGenerator [OPTION]... PAGE...
|
||||
site-generator [OPTION]... PAGE...
|
||||
|
||||
-p, --preview print generated pages to standard out
|
||||
-v, --verbose use verbose mode
|
||||
--help print this help message
|
||||
|
||||
@ -40,7 +41,7 @@ This is a site generator for the Hacker Public Radio website based upon the Perl
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Roan Horning <roan.horning@no-spam.gmail.com>
|
||||
Roan Horning <roan.horning@no-spam.gmail.com>
|
||||
|
||||
=cut
|
||||
|
||||
@ -51,14 +52,17 @@ use Getopt::Long qw(:config auto_help);
|
||||
use Pod::Usage;
|
||||
use Config::Std;
|
||||
use Template;
|
||||
use Data::Dumper;
|
||||
|
||||
exit main();
|
||||
|
||||
sub main {
|
||||
|
||||
# Argument parsing
|
||||
my $preview;
|
||||
my $verbose;
|
||||
GetOptions(
|
||||
'preview' => \$preview,
|
||||
'verbose' => \$verbose,
|
||||
) or pod2usage(1);
|
||||
pod2usage(1) unless @ARGV;
|
||||
@ -86,7 +90,7 @@ sub main {
|
||||
|
||||
if (exists($config{$page})) {
|
||||
verbose ($verbose, "Generating page: $page");
|
||||
generate_page($tt, $config{root_template}{content}, $config{$page}{navigation}, $config{$page}{content});
|
||||
generate_page($tt, $config{root_template}{content}, \%config, $page, $preview);
|
||||
|
||||
}
|
||||
else {
|
||||
@ -104,6 +108,7 @@ sub get_template_html (\%@) {
|
||||
#
|
||||
return Template->new({
|
||||
INCLUDE_PATH => './templates',
|
||||
OUTPUT_PATH => './public_html',
|
||||
EVAL_PERL => 1,
|
||||
START_TAG => '<!--%',
|
||||
END_TAG => '%-->',
|
||||
@ -117,13 +122,13 @@ sub get_template_html (\%@) {
|
||||
}
|
||||
|
||||
sub generate_page {
|
||||
my ($tt, $page, $navigation, $content) = @_;
|
||||
my $tt_vars = {
|
||||
navigation => $navigation,
|
||||
content => $content
|
||||
};
|
||||
my ($tt, $root_template, $config, $page, $preview) = @_;
|
||||
|
||||
$tt->process($page, $tt_vars)
|
||||
my $html;
|
||||
if (!$preview) {
|
||||
$html = "$page.html";
|
||||
}
|
||||
$tt->process($root_template, $config->{$page}, $html)
|
||||
|| die $tt->error(), "\n";
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user