From dfaae392024d3749cf63e63203345e0332881cf7 Mon Sep 17 00:00:00 2001 From: Roan Horning Date: Fri, 1 Jul 2022 22:02:25 -0400 Subject: [PATCH] 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. --- site-generator | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/site-generator b/site-generator index a984089..d98a501 100755 --- a/site-generator +++ b/site-generator @@ -11,7 +11,8 @@ siteGenerator - HPR Site Generator -v, --verbose use verbose mode --help print this help message - Where I is a file name of a web page. + Where I 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 "."; + }; +}