common: preferred external url in canonical link
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 27 Dec 2023 18:06:50 +0000 (19:06 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 28 Dec 2023 07:19:58 +0000 (08:19 +0100)
Coalesce similar or identical pages in (Google) search results and rankings.
Without further cleanup, the requested paths seem a sufficient target for
all pages except for charset (significant option to be maintained) and
keyboard (legacy shorthands).

charset.plp
common.inc.plp
keyboard.plp

index 33f02c7428db0d7cb08381e913e0068f8ca5a4d8..bbab1d6b83868e67e4619e94db05b88e67d8ce65 100644 (file)
@@ -6,6 +6,7 @@ my @tablist = split m{/+}, $Request || 'default';
 Html({
        title => 'charset cheat sheet',
        version => '1.3',
+       canonical => "/charset/$Request" . ($mode && '?compare'),
        description => [
                "Reference sheet with all glyphs in common character encoding tables,",
                "and an overview of Unicode ranges and UTF-8 bytes.",
index 6295de7ef2ad0653fc436d9636831349742ee832..9d341284e1ba20869e2634d695c23ace8f52c6c7 100644 (file)
@@ -157,6 +157,11 @@ sub Html {
 
        my ($file) = $ENV{SCRIPT_FILENAME} =~ m{ ([^/]+) \.plp$ }x;
 
+       if (my $url = $meta->{canonical} // "/$file/$Request") {
+               $url = "https://sheet.shiar.nl$url";
+               push @{ $meta->{raw} }, qq(<link rel="canonical" href="$url" />);
+       }
+
        PLP_START {
                # leading output
                say '<!DOCTYPE html>';
index 62e150a7dd726b75c4d1d9ba0f4898a837b149ef..e4ba72da23a61720a847b547989228d404f9dd0b 100644 (file)
@@ -26,6 +26,7 @@ if ($Request =~ /^altgr/ and open my $cssinc, '<', 'keyboard/altgr.css') {
 Html({
        title => "\L$mode\E keyboard cheat sheet",
        version => $info->{version} || '0.1',
+       canonical => -e "$Request.plp" ? "/$Request" : undef, # historic shorthand
        description => $info->{description} //
                ["Keyboard cheat sheet for the default controls of $mode."],
        keywords => [@{ $info->{keywords} // [] }, qw'