From a9373583829e281016f414287d0dfc16aae8ec4f Mon Sep 17 00:00:00 2001 From: Duncan Bayne Date: Mon, 23 Sep 2024 22:23:49 +1000 Subject: [PATCH] Fix custom descriptions in OG tags --- lib/Halp/Generator.pm | 10 +++++----- t/expected/www/blog/2023-05-07_second-article.html | 2 +- .../blog/.2023-05-07_second-article.html.description | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 t/fixtures/www/blog/.2023-05-07_second-article.html.description diff --git a/lib/Halp/Generator.pm b/lib/Halp/Generator.pm index 955ce5f..be03122 100644 --- a/lib/Halp/Generator.pm +++ b/lib/Halp/Generator.pm @@ -103,8 +103,12 @@ sub wrap_page_template { $description = read_file($description_pathname); $description =~ s/\s+/ /; } + + if ($description =~ /^(.*?[\.\?\!])/) { + $description = $1; + } } else { - my $description_pathname = File::Spec->catfile($source_dirname, ".$source_basename.description.$self->{template_type}"); + my $description_pathname = File::Spec->catfile($source_dirname, ".$source_basename.description"); if (-f $description_pathname) { $description = read_file($description_pathname); $description =~ s/\s+/ /; @@ -117,10 +121,6 @@ sub wrap_page_template { default { die 'Unsupported template type'; } } - if ($description =~ /^(.*?[\.\?\!])/) { - $description = $1; - } - $description = encode_entities($description); chomp($description); diff --git a/t/expected/www/blog/2023-05-07_second-article.html b/t/expected/www/blog/2023-05-07_second-article.html index 430bd89..47157fa 100644 --- a/t/expected/www/blog/2023-05-07_second-article.html +++ b/t/expected/www/blog/2023-05-07_second-article.html @@ -17,7 +17,7 @@ - + diff --git a/t/fixtures/www/blog/.2023-05-07_second-article.html.description b/t/fixtures/www/blog/.2023-05-07_second-article.html.description new file mode 100644 index 0000000..59ef6dd --- /dev/null +++ b/t/fixtures/www/blog/.2023-05-07_second-article.html.description @@ -0,0 +1 @@ +A custom description! -- 2.45.2