Allow multiple pages to be generated from one template
Feature to allow generation of host and episode pages.
This commit is contained in:
@@ -6,14 +6,14 @@
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
site-generator [OPTION]... PAGE...
|
||||
site-generator [OPTION]... PAGE|PAGE=<comma separated list of ids>...
|
||||
|
||||
-p, --preview print generated pages to standard out
|
||||
-v, --verbose use verbose mode
|
||||
--help print this help message
|
||||
|
||||
Where I<PAGE> is a file name of a web page
|
||||
or the special ALL (to generate all pages).
|
||||
or the special I<ALL> (to generate all pages).
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
Generate the whole site:
|
||||
site-generator ALL
|
||||
|
||||
Generate pages based on the same template:
|
||||
site-generator correspondent=1,3,5..10
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This is a site generator for the Hacker Public Radio website based upon the Perl Templates Toolkit.
|
||||
@@ -105,20 +108,24 @@ sub main {
|
||||
|
||||
# Remove non page sections of the configuration file
|
||||
# from the generated list of pages.
|
||||
@page_args= grep { $_ ne 'DBI' } @pages_args;
|
||||
@page_args= grep { $_ ne 'DBI' } @page_args;
|
||||
@page_args= grep { $_ ne 'root_template' } @page_args;
|
||||
};
|
||||
foreach my $page_arg (@page_args) {
|
||||
my %page_arg = parse_page_arg($page_arg);
|
||||
|
||||
if (exists($config{$page_arg{'page'}})) {
|
||||
my $page_config = $config{$page_arg{'page'}};
|
||||
$page_config->{'page'} = $page_arg{'page'};
|
||||
my %parsed_arg = parse_page_arg($page_arg);
|
||||
if (exists($config{$parsed_arg{'page'}})) {
|
||||
my $page_config = $config{$parsed_arg{'page'}};
|
||||
$page_config->{'page'} = $parsed_arg{'page'};
|
||||
|
||||
if ($page_config->{'multipage'}) {
|
||||
print "multipage\n";
|
||||
foreach my $id ($page_config->{'ids'}) {
|
||||
if ($page_config->{'multipage'} && $page_config->{'multipage'} eq 'true') {
|
||||
if (scalar @{$parsed_arg{'ids'}} == 1) {
|
||||
@{$parsed_arg{'ids'}} = get_ids_from_db($tt, \$page_config);
|
||||
}
|
||||
foreach my $id (@{$parsed_arg{'ids'}}) {
|
||||
$page_config->{'id'} = $id;
|
||||
verbose ($verbose, "Generating page: $page_config->{'page'} with id: $id");
|
||||
generate_page($tt, $config{root_template}{content}, \$page_config, $preview);
|
||||
print "$page_config->{'page'} $page_config->{'id'}\n";
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -127,7 +134,7 @@ sub main {
|
||||
}
|
||||
}
|
||||
else {
|
||||
verbose (1, "\nWarning: Page $page_arg{'page'} is not defined in the configuration file.");
|
||||
verbose (1, "\nWarning: Page $parsed_arg{'page'} is not defined in the configuration file.");
|
||||
}
|
||||
}
|
||||
verbose (1, "\nFinished processing the files.");
|
||||
@@ -158,7 +165,6 @@ sub get_template_html (\%@) {
|
||||
|
||||
sub generate_page {
|
||||
my ($tt, $root_template, $config, $preview) = @_;
|
||||
print Dumper($$config);
|
||||
my $html;
|
||||
if (!$preview) {
|
||||
$html = get_filename($$config);
|
||||
@@ -203,7 +209,22 @@ sub parse_page_arg {
|
||||
}
|
||||
}
|
||||
}
|
||||
return ('page', $page, 'ids', @ids);
|
||||
return ('page' => $page, 'ids' => [@ids]);
|
||||
}
|
||||
|
||||
sub get_ids_from_db {
|
||||
# Use a template to generate a string of page identifiers.
|
||||
# The template should return the string in the form of
|
||||
# <comma><identifier><comma><identifier>...
|
||||
#
|
||||
my ($tt, $config) = @_;
|
||||
my $selected_ids = "";
|
||||
my $id_template = "ids-$$config->{'page'}.tpl.html";
|
||||
|
||||
$tt->process($id_template, $$config, \$selected_ids)
|
||||
|| die $tt->error(), "\n";
|
||||
|
||||
return split(/,/, substr($selected_ids, 1));
|
||||
}
|
||||
|
||||
sub get_filename {
|
||||
|
Reference in New Issue
Block a user