From 3f766544acc196364dd8a74efe31772b75bcd00b Mon Sep 17 00:00:00 2001 From: Dave Morriss Date: Sun, 23 Jul 2023 17:03:27 +0100 Subject: [PATCH] I145 Various bug fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit site-generator: fixed an error in the POD documentation and added an example. Reformatted 'GetOptions' arguments. Fixed 'parse_page_arg' which started its returned array with an empty arrayref. Fixed code using this array which skipped this unwanted extra value. Fixed 'get_ids_from_db' which turns a CSV list of shows into an array, but includes a blank element. Removed a few trailing spaces. templates/content-correspondents.tpl.html: Capitalised "License". Added 'order by h.host' to the internal query to get hosts sorted alphabetically. templates/content-episode.tpl.html: Added a call to macro 'zero_pad_left' to add leading zeroes to show number in the title. Added a call to 'FILTER html_para' when displaying comments (which are plain text). Added a test for whether the show being displayed is in the 20-show window before the current one to determine whether the short or long comment form is required. Added the code to generate the two form types depending on the earlier test. templates/content-sitemap.tpl.html: Corrected the entry for "Show Comments" which contained an invalid URL. templates/page.tpl.html: Grammar corrections in the '' section. templates/queries-episode-mysql.tpl.html: Adjusted the date tests in the CTE's which compare the episode date with today's date plus one day. Why add a day when the test is whether the episode date is less than or equal to the current one? Also, it seemed that MySQL/MariaDB might need to work with the UTC date rather than the local dat implied by 'NOW()'. templates/queries-episode-sqlite.tpl.html: Similar adjustment to date tests in CTE's to the MySQL version. SQLite defaults to UTC however. templates/queries-episodes-mysql.tpl.html: See above for notes about date tests and MySQL UTC dates. Same arguments here. templates/queries-episodes-sqlite.tpl.html: Date test adjustment described above. templates/queries-ids-episode-mysql.tpl.html: Removed the date test from the query so all episode numbers are returned. Added an 'order by' since the table can (could in the past) return numbers out of numerical sequence. templates/queries-ids-episode-sqlite.tpl.html: Same change as for the MySQL version. templates/queries-index-mysql.tpl.html: There are three queries here, returned as TT² variables. The one called 'query_latest_episodes' has been adjusted to use UTC and to avoid adding a day to the current date. The query called 'query_last_5_weeks_episodes' has been similarly adjusted. templates/queries-index-sqlite.tpl.html: Changes for the same two queries, but just for the tests requiring today's date plus one day. templates/rss-comments.tpl.xml: Grammar corrections in the '' section. templates/rss.tpl.xml: Grammar corrections in various subsections of the '' section. templates/shared-call_for_shows.tpl.html: Removed the "FTP server" message. Slight tidying. --- site-generator | 44 +++++++++++-------- templates/content-correspondents.tpl.html | 5 ++- templates/content-episode.tpl.html | 42 +++++++++++++++--- templates/content-sitemap.tpl.html | 2 +- templates/page.tpl.html | 2 +- templates/queries-episode-mysql.tpl.html | 8 ++-- templates/queries-episode-sqlite.tpl.html | 6 +-- templates/queries-episodes-mysql.tpl.html | 2 +- templates/queries-episodes-sqlite.tpl.html | 2 +- templates/queries-ids-episode-mysql.tpl.html | 4 +- templates/queries-ids-episode-sqlite.tpl.html | 4 +- templates/queries-index-mysql.tpl.html | 4 +- templates/queries-index-sqlite.tpl.html | 4 +- templates/rss-comments.tpl.xml | 2 +- templates/rss.tpl.xml | 6 +-- templates/shared-call_for_shows.tpl.html | 3 +- 16 files changed, 86 insertions(+), 54 deletions(-) diff --git a/site-generator b/site-generator index c81cffc..1147b68 100755 --- a/site-generator +++ b/site-generator @@ -8,13 +8,13 @@ site-generator [OPTION]... PAGE|PAGE=... - -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 + -a, --all generate all pages defined in configuration file + -c, --configuration 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). @@ -30,6 +30,10 @@ Generate pages based on the same template: site-generator correspondent=1,3,5..10 + Generate two specific pages with a different configuration: + site-generator --configuration=site_sqlite.cfg index about + + =head1 DESCRIPTION This is a site generator for the Hacker Public Radio website based upon the Perl Templates Toolkit. @@ -115,12 +119,12 @@ sub main { my $verbose; my $quiet; GetOptions( - 'all' => \$all, + 'all' => \$all, 'configuration=s' => \$configuration_path, - 'list' => \&print_available_pages, - 'preview' => \$preview, - 'verbose' => \$verbose, - 'quiet' => \$quiet, + 'list' => \&print_available_pages, + 'preview' => \$preview, + 'verbose' => \$verbose, + 'quiet' => \$quiet, ) or pod2usage(1); pod2usage(1) unless @ARGV || $all; my (@page_args) = @ARGV; @@ -179,8 +183,10 @@ sub main { } 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); + # Empty arrayref bug fixed, so count is reduced by 1 +# if (scalar @{$parsed_arg{'ids'}} == 1) { + if (scalar @{$parsed_arg{'ids'}} == 0) { + @{$parsed_arg{'ids'}} = get_ids_from_db($tt, \$page_config); } foreach my $id (@{$parsed_arg{'ids'}}) { $page_config->{'id'} = $id; @@ -252,7 +258,8 @@ sub parse_page_arg { my ($page_arg) = @_; # Split page name from page ids if available. my ($page, $ids) = split(/=/, $page_arg); - my @ids = []; + #my @ids = []; + my @ids; if(!$ids) { $ids = ""; @@ -287,8 +294,9 @@ sub get_ids_from_db { $tt->process($id_template, $$config, \$selected_ids) || die $tt->error(), "\n"; - - return split(/,/, substr($selected_ids, 1)); + + # Starts with a newline and comma + return split(/,/, substr($selected_ids, 2)); } sub get_filename { @@ -313,7 +321,7 @@ sub get_filename { # Default naming if full filename configuration is not supplied. if ($$config{'multipage'} && $$config{'multipage'} eq 'true') { my $padded_index = sprintf("%04d", $$config{'id'}); - $filename = "$base_path$$config{'page'}${padded_index}.html"; + $filename = "$base_path$$config{'page'}${padded_index}.html"; } else { $filename = "$base_path$$config{'page'}.html"; diff --git a/templates/content-correspondents.tpl.html b/templates/content-correspondents.tpl.html index dce4335..6e5eb68 100644 --- a/templates/content-correspondents.tpl.html +++ b/templates/content-correspondents.tpl.html @@ -8,14 +8,15 @@ - + diff --git a/templates/content-episode.tpl.html b/templates/content-episode.tpl.html index 3689e13..4515096 100644 --- a/templates/content-episode.tpl.html +++ b/templates/content-episode.tpl.html @@ -5,14 +5,14 @@ - + + @@ -87,13 +87,41 @@ Subscribe to the comments - + + + + + + + + + + + + + + + + + + +
Avatar Name & Host IDlicenseLicense Last Show
Comment:
+
Are you a spammer? + + + + +
Who hosted this show? + + +
What does HPR mean to you?
+
diff --git a/templates/content-sitemap.tpl.html b/templates/content-sitemap.tpl.html index 873328a..0bef9fe 100644 --- a/templates/content-sitemap.tpl.html +++ b/templates/content-sitemap.tpl.html @@ -27,7 +27,7 @@
  • Hosts ← A list of all our Hosts.
  • Contact ← How to get in touch with us.
  • Promote HPR ← Ways you can spread the word.
  • -
  • Show Comments ← Read the latest comments left on shows.
  • +
  • Show Comments ← Read the latest comments left on shows.
  • Search ← Search HPR
  • diff --git a/templates/page.tpl.html b/templates/page.tpl.html index 837e384..9d8aca3 100644 --- a/templates/page.tpl.html +++ b/templates/page.tpl.html @@ -11,7 +11,7 @@ - +