From 14bafbc3ab571b3643c94fd500377e2f5b4bb1cb Mon Sep 17 00:00:00 2001 From: Roan Horning Date: Wed, 8 Mar 2023 22:23:56 -0500 Subject: [PATCH 1/2] Add command line option for path to configuration file Allow user to pass the path to the configuration file into the site-generator. --- site-generator | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/site-generator b/site-generator index 61b515b..42331f0 100755 --- a/site-generator +++ b/site-generator @@ -8,12 +8,13 @@ site-generator [OPTION]... PAGE|PAGE=... - -a, --all generate all pages defined in configuration file - -l, --list print list of configured pages - -p, --preview print generated pages to standard out - -q, --quiet suppress progress information while generating pages - -v, --verbose print extended progress information while generating pages - --help print this help message + -a, --all generate all pages defined in configuration file + -c, --configure path to configuration file + -l, --list print list of configured pages + -p, --preview print generated pages to standard out + -q, --quiet suppress progress information while generating pages + -v, --verbose print extended progress information while generating pages + --help print this help message Where I is a file name of a web page or the special I (to generate all pages). @@ -109,15 +110,17 @@ sub main { # Argument parsing my $all; + my $configuration_path; my $preview; my $verbose; my $quiet; GetOptions( - 'all' => \$all, - 'list' => \&print_available_pages, - 'preview' => \$preview, - 'verbose' => \$verbose, - 'quiet' => \$quiet, + 'all' => \$all, + 'configuration=s' => \$configuration_path, + 'list' => \&print_available_pages, + 'preview' => \$preview, + 'verbose' => \$verbose, + 'quiet' => \$quiet, ) or pod2usage(1); pod2usage(1) unless @ARGV || $all; my (@page_args) = @ARGV; @@ -126,8 +129,19 @@ sub main { $verbose = 'quiet'; }; - # Load config file - read_config "site.cfg" => my %config; + if (!$configuration_path) { + $configuration_path = "site.cfg"; + } + + my %config; + if ( -f $configuration_path ) { + # Load config file + read_config $configuration_path => %config; + } + else { + print STDOUT "Could not read configuration file: $configuration_path\n"; + exit 1; + } my $tt = get_template_html($config{DBI}); From f65e8921821497a87788d38a7c9a8ec97eb4d21b Mon Sep 17 00:00:00 2001 From: Roan Horning Date: Thu, 9 Mar 2023 20:25:25 -0500 Subject: [PATCH 2/2] Add template and HTML folder configuration options Allow user to set the path for the website templates and output folders in the site.cfg file. --- site-generator | 8 ++++---- site.cfg | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/site-generator b/site-generator index 42331f0..1171443 100755 --- a/site-generator +++ b/site-generator @@ -143,7 +143,7 @@ sub main { exit 1; } - my $tt = get_template_html($config{DBI}); + my $tt = get_template_html($config{DBI}, $config{app_paths}); # If command line option all is set, parse configuration file # for all pages @@ -154,7 +154,7 @@ sub main { # from the generated list of pages. @page_args= grep { $_ ne 'DBI' } @page_args; @page_args= grep { $_ ne 'root_template' } @page_args; - @page_args= grep { $_ ne 'media_hostname' } @page_args; + @page_args= grep { $_ ne 'app_paths' } @page_args; }; foreach my $page_arg (@page_args) { @@ -207,8 +207,8 @@ sub get_template_html (\%@) { # HTML comments to make the template file valid HTML. # return Template->new({ - INCLUDE_PATH => './templates', - OUTPUT_PATH => './public_html', + INCLUDE_PATH => $_[1]{templates_path}, + OUTPUT_PATH => $_[1]{output_path}, EVAL_PERL => 1, START_TAG => '', diff --git a/site.cfg b/site.cfg index cc5c037..aefadb2 100644 --- a/site.cfg +++ b/site.cfg @@ -13,6 +13,11 @@ #user: hpr-generator (Suggested user with read-only privileges) #password: ********* (Password for user) +# Configure the location of the templates and the generated HTML +[app_paths] +templates_path: ./templates +output_path: ./public_html + # Configure the root template page which pulls in the navigation and # content templates used by each page. An optional baseurl property may # be defined. This is useful when opening files directly from local