common: format page attribute "image" as og header
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 19 Dec 2023 18:13:39 +0000 (19:13 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 20 Dec 2023 00:27:29 +0000 (01:27 +0100)
Shared code to ascertain absolute urls.

common.inc.plp
dieren.plp
sample.plp

index 2976cbe37cd07615b1f9073d9fc332b403e19e24..6295de7ef2ad0653fc436d9636831349742ee832 100644 (file)
@@ -147,6 +147,14 @@ sub Html {
                '<link rel="stylesheet" type="text/css" media="monochrome" href="/mono.css?1.11" title="light">',
        );
 
+       if (my $img = $meta->{image}) {
+               my $proto = sprintf('http%s://', !!$ENV{HTTPS} && 's');
+               my $url = "$proto$ENV{HTTP_HOST}/$img";
+               push @{ $meta->{raw} }, (
+                       qq(<meta property="og:image" content="$url" />),
+               );
+       }
+
        my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x;
 
        PLP_START {
index f7935fee7562cc61ab4bb820138c1cd62421c73d..03d0dc91e670121a189677f618f04ee235317f0a 100644 (file)
@@ -32,9 +32,6 @@ $Request ||= 'standaard';
 my $pageinfo = $subpages{$Request}
        or Html(), Abort("Onbekende dierenpagina <q>$Request</q>", '404 request not found');
 
-my $proto = sprintf('http%s://', !!$ENV{HTTPS} && 's');
-my $preview = "$proto$ENV{HTTP_HOST}/dieren.jpg";
-
 Html({
        title => $pageinfo->{title}.' cheat sheet',
        version => '1.1',
@@ -45,8 +42,8 @@ Html({
                relatie vernoemd vernoeming combinatie samenstelling voorvoegsel onverwant
                land zee lucht  animals dutch language
        '],
+       image => 'dieren.jpg',
        raw => <<"EOT",
-<meta property="og:image" content="$preview" />
 <style>
 figure[hidden] {
        opacity: 0; /* secret */
index 12460ec14e7db44624436747056a16bb6b4bc697..36ad2b424e995697c25e7a6602e94b8c18cb0158 100644 (file)
@@ -1,15 +1,13 @@
 <(common.inc.plp)><:
 
 my $textinc = 'sample.txt';
-my $proto = sprintf('http%s://', !!$ENV{HTTPS} && 's');
-my $preview = "$proto$ENV{HTTP_HOST}/sample.png";
 
 Html({
        title => "unicode sampler",
        version => '2.1',
        stylesheet => [qw'light dark mono red'],
        data => [$textinc],
-       raw => qq(<meta property="og:image" content="$preview" />),
+       image => 'sample.png',
 });
 
 open my $source, '<', $textinc