Skip to content
Snippets Groups Projects
Commit 92863f1b authored by Síle Ekaterin Liszka's avatar Síle Ekaterin Liszka
Browse files

Chessa::URI::Plugin::Default: ld_json() displays author & publication date

parent 96fbff0a
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment