Initial add of multipage template processing

For the individual host pages, allow the ids to be passed
in on the command line.
This commit is contained in:
Roan Horning 2022-07-21 23:58:30 -04:00
parent 4e56289338
commit 1ec288bbb8
Signed by: rho_n
GPG Key ID: 234AEF20B72D5769

View File

@ -109,14 +109,20 @@ sub main {
@pages= grep { $_ ne 'root_template' } @pages;
};
foreach my $page (@pages) {
my %pages = get_multiple_pages($page);
if (exists($config{$pages{'page'}})) {
if ($config{$pages{'page'}}{'multipage'}) {
foreach my $id ($pages{'ids'}) {
if (exists($config{$page})) {
verbose ($verbose, "Generating page: $page");
generate_page($tt, $config{root_template}{content}, \%config, $page, $preview);
}
}
else {
verbose ($verbose, "Generating page: $pages{'page'}");
generate_page($tt, $config{root_template}{content}, \%config, $pages{'page'}, $preview);
}
}
else {
verbose (1, "\nWarning: Page $page is not defined in the configuration file.");
verbose (1, "\nWarning: Page $pages{'page'} is not defined in the configuration file.");
}
}
verbose (1, "\nFinished processing the files.");
@ -166,3 +172,32 @@ sub verbose {
print ".";
};
}
sub get_multiple_pages {
my ($pages) = @_;
# Split page name from page ids if available.
my ($page, $ids) = split(/=/, $pages);
my @ids = [];
if(!$ids) {
$ids = "";
}
else {
# Parse the page ids and push them onto @ids array
my @ids_by_comma = split(/\,/, $ids);
foreach my $id_by_comma (@ids_by_comma) {
my @ids_for_range = split(/\.\./, $id_by_comma);
if ((scalar @ids_for_range) == 2) {
push @ids, $ids_for_range[0]..$ids_for_range[1];
}
elsif ((scalar @ids_for_range) == 1) {
push @ids, $ids_for_range[0];
}
else {
verbose (1, "\nWarning: Page $page id range $id_by_comma could not be parsed.");
}
}
}
return ('page', $page, 'ids', @ids);
}