codec: page specific keywords from include data
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 19 Mar 2023 14:27:25 +0000 (15:27 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 13 Apr 2023 12:08:42 +0000 (14:08 +0200)
codec-audio.inc.pl
codec-image.inc.pl
codec.plp

index 5844ea07ba9922f3b108a4ea169d023624db882e..330f3b58c26c45f1e6d0fdf30c6ec1470d1696b8 100644 (file)
@@ -1,6 +1,7 @@
 use utf8;
 +{
 intro => 'Comparison of audio compression formats.',
+keywords => [qw( audio sound codec encoder encoding decode compression file format type mime )],
 codec => {
        mp3 => {
                name => '<abbr title="MPEG-1 Audio Layer III">MP3</abbr>',
index f689142f41f6313572ad48b58b3c4206d36ce5ff..6c138abcd5a34ebe548541a7024fe821ba52684e 100644 (file)
@@ -1,6 +1,7 @@
 use utf8;
 +{
 intro => 'Comparison of image encoding formats, based on <a href="https://cloudinary.com/blog/one_pixel_is_worth_three_thousand_words">Cloudinary</a> research.',
+keywords => [qw( image picture codec encoder encoding decode compression file format type mime )],
 codec => {
        jpeg => {
                name => '<abbr title="Joint Photographic Experts Group">JPEG</abbr>',
index 5c3e572e1023241ef0cb3cb75f371ff44bbd1683..05fe30e0bb4b08f9f2dbe5a51e5d5486aa6ccc28 100644 (file)
--- a/codec.plp
+++ b/codec.plp
@@ -4,25 +4,23 @@ my ($page, @feat) = split m{/+}, $Request || 'image';
 $page !~ /\W/ or Html(), Abort('Invalid codec type request', 400);
 @feat or @feat = 'default';
 my $title = "$page codecs";
+my $info = eval { Data("codec-$page") };
+if ($@) {
+       $info = {};
+}
 
 Html({
        title => "$title cheat sheet",
        version => '1.0',
-       description => [
-       ],
-       keywords => [qw'
-               codec encoder encoding decode file format type mime
-               feature comparison support benchmark compression
-               image audio video
-       '],
+       description => $info->{intro},
+       keywords => [@{ $info->{keywords} // [] }, qw' feature comparison support benchmark '],
        stylesheet => [qw'light circus dark red'],
        data => ["codec-$page.inc.pl"],
        raw => '<style>td,th {width:8%} tbody th {white-space:nowrap}</style>',
 });
 
-my $info = Data("codec-$page");
-$info and %{$info} > 1
-       or Abort("Requested codec type <q>$page</q> not available", '404 request not found', $@ // $!);
+%{$info}
+       or Abort("Requested codec type <q>$page</q> not available", '404 request not found');
 
 say "<h1>\u$title</h1>";
 say "<p>$_</p>" for $info->{intro} // ();