Add logic to process file arguments

Process all files if the special ALL argument is passed in, or
process the list of files passed in as arguments.
This commit is contained in:
Roan Horning 2022-07-01 22:02:25 -04:00
parent dd8b9b655b
commit dfaae39202
No known key found for this signature in database
GPG Key ID: 6E07059BD168E395

View File

@ -11,7 +11,8 @@ siteGenerator - HPR Site Generator
-v, --verbose use verbose mode
--help print this help message
Where I<PAGE> is a file name of a web page.
Where I<PAGE> is a file name of a web page
or the special ALL (to generate all pages).
Examples:
@ -51,12 +52,36 @@ sub main {
pod2usage(1) unless @ARGV;
my (@pages) = @ARGV;
# Set flag indicating whether or not to generate all pages.
# The flag is set to true if the special argument ALL is
# passed into the generator
my $ALL = grep { $_ eq 'ALL' } @pages;
# Load config file
read_config "site.cfg" => my %config;
my $tt = get_template_html($config{DBI});
generate_page($tt, $config{root_template}{content}, $config{correspondents}{navigation}, $config{correspondents}{content});
if ($ALL) {
@pages = keys %config;
# Remove non page sections of the configuration file
# from the generated list of pages.
@pages= grep { $_ ne 'DBI' } @pages;
@pages= grep { $_ ne 'root_template' } @pages;
};
foreach my $page (@pages) {
if (exists($config{$page})) {
verbose ($verbose, "Generating page: $page");
generate_page($tt, $config{root_template}{content}, $config{$page}{navigation}, $config{$page}{content});
}
else {
verbose (1, "\nWarning: Page $page is not defined in the configuration file.");
}
}
verbose (1, "\nFinished processing the files.");
return 0;
}
@ -91,3 +116,12 @@ sub generate_page {
}
sub verbose {
my ($verbose, $message) = @_;
if ($verbose) {
print "$message\n";
}
else {
print ".";
};
}