From 92863f1bf7f4e2f773e6a980d1c55e92bd73f178 Mon Sep 17 00:00:00 2001 From: Kiyoshi Aman <sheila@vulpine.house> Date: Thu, 27 Oct 2022 01:11:36 -0700 Subject: [PATCH] Chessa::URI::Plugin::Default: ld_json() displays author & publication date --- scripts/Chessa/URI/Plugin/Default.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/Chessa/URI/Plugin/Default.pm b/scripts/Chessa/URI/Plugin/Default.pm index 80b1b0c..395bdc1 100644 --- a/scripts/Chessa/URI/Plugin/Default.pm +++ b/scripts/Chessa/URI/Plugin/Default.pm @@ -160,8 +160,9 @@ sub get { $t->parse_content($response->decoded_content); my $title = undef; - # Try to use AMP to get information, since some sites are more informative with AMP than they are with regular HTML. - # Because, y'know, why be useful to everyone when Google's the only people who matter? + # Try to use AMP to get information, since some sites are more informative + # with AMP than they are with regular HTML. Because, y'know, why be useful + # to everyone when Google's the only people who matter? if ($t->exists('//script[@type="application/ld+json"]')) { $title = $self->ld_json($t, $authority); goto TITLE unless defined($title); @@ -169,7 +170,8 @@ sub get { TITLE: # Check meta elements for useful information (e.g. for Mastodon) # XXX: May need to do some extra sniffing here. - if ($t->exists('//meta[@property="twitter:card"]')) { + if ($t->exists('//meta[@property="twitter:card"]') || + $t->exists('//meta[@property="og:title]')) { $title = $self->tcard($t, $authority); } else { # This is not an AMP page and doesn't provide a twitter card. @@ -251,7 +253,11 @@ sub ld_json { } elsif (($json->{'@type'} eq 'NewsArticle') && (exists($json->{headline}))) { my $title = $json->{headline}; $title =~ s/^\s+//; $title =~ s/\s+$//; - return $self->{msg}($authority, $json->{headline}); + my $published = $json->{datePublished}; + my $author = $json->{author}{name}; + return $self->{msg}($authority, $json->{headline}) . ' ' . + $self->{msg}('Author', $author) . ' ' . + $self->{msg}('Published', $published); } } @@ -270,6 +276,8 @@ sub tcard { my $text = $t->findvalue('//meta[@property="twitter:description"]/@content'); if ($text eq '') { $text = $t->findvalue('//meta[@property="og:description"]/@content') }; $text =~ s/\r?\n/ /g; + my $published = $t->findvalue('//meta[@property="article:published_time'); + my $modified = $t->findvalue('//meta[@property="article:modified_time'); if (length($text) > 390) { my @text = split ' ', $text; -- GitLab