- NewsArticle + BreadcrumbList JSON-LD (headline, summary, images, ISO dates, authors, GOOI&meer as NewsMediaOrganization publisher, section) - Per-article meta description instead of the generic site text - article:published_time / modified_time in ISO 8601 (was og:article:* in RFC 2822), article:section / article:tag, og:image:alt, og:locale nl_NL - Canonical URL, twitter:card, robots max-image-preview:large - <html lang="nl">, title without leading whitespace, no keywords meta - Article wrapped in <article>, dates in <time datetime> - Metadata is rebuilt after the controller fills in API v2 data (dates, author, content blocks were not reflected before) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
67 lines
2.8 KiB
PHP
67 lines
2.8 KiB
PHP
{{--
|
|
Structured data (schema.org JSON-LD) for a news article: NewsArticle with
|
|
GOOI&meer as publisher, and the breadcrumb. Used by search engines (Google
|
|
News / Top Stories) and AI assistants to understand the article.
|
|
--}}
|
|
@php
|
|
$canonical = url()->current();
|
|
$absolute = function ($image) use ($imgBase) {
|
|
return $image['own'] ? $imgBase . $image['url'] : $image['url'];
|
|
};
|
|
$images = array_map($absolute, $news->imageList());
|
|
$tags = $news->tagTitles();
|
|
|
|
// "Saskia Plokker, Bart Koomen" / "A en B" -> separate authors;
|
|
// an affiliation in brackets ("Elsa Poorthuis (Gooi & Meer)") is dropped
|
|
$authors = [];
|
|
$authorText = preg_replace('/\s*\([^)]*\)/u', '', trim(strip_tags((string) $news->author)));
|
|
foreach (preg_split('/\s*(?:,|\s&\s|\s+en\s+)\s*/u', $authorText) as $name) {
|
|
if ($name !== '') {
|
|
$authors[] = ['@type' => 'Person', 'name' => $name];
|
|
}
|
|
}
|
|
|
|
$publisher = [
|
|
'@type' => 'NewsMediaOrganization',
|
|
'@id' => rtrim(url('/'), '/') . '/#organization',
|
|
'name' => 'GOOI&meer',
|
|
'url' => url('/'),
|
|
'logo' => [
|
|
'@type' => 'ImageObject',
|
|
'url' => url('/android-chrome-512x512.png'),
|
|
'width' => 512,
|
|
'height' => 512,
|
|
],
|
|
];
|
|
|
|
$article = array_filter([
|
|
'@type' => 'NewsArticle',
|
|
'@id' => $canonical . '#article',
|
|
'mainEntityOfPage' => ['@type' => 'WebPage', '@id' => $canonical],
|
|
'url' => $canonical,
|
|
'headline' => mb_substr($news->plainTitle(), 0, 110),
|
|
'description' => $news->summary(200),
|
|
'image' => $images ?: null,
|
|
'datePublished' => $news->published ? $news->published->format(DATE_ATOM) : null,
|
|
'dateModified' => ($news->edited ?: $news->published) ? ($news->edited ?: $news->published)->format(DATE_ATOM) : null,
|
|
'author' => $authors ?: $publisher,
|
|
'publisher' => $publisher,
|
|
'articleSection' => $tags[0] ?? null,
|
|
'keywords' => $tags ? implode(', ', $tags) : null,
|
|
'inLanguage' => 'nl-NL',
|
|
'isAccessibleForFree' => true,
|
|
]);
|
|
|
|
$breadcrumb = [
|
|
'@type' => 'BreadcrumbList',
|
|
'itemListElement' => [
|
|
['@type' => 'ListItem', 'position' => 1, 'name' => 'Home', 'item' => url('/')],
|
|
['@type' => 'ListItem', 'position' => 2, 'name' => 'Nieuws', 'item' => route('nieuws')],
|
|
['@type' => 'ListItem', 'position' => 3, 'name' => $news->plainTitle(), 'item' => $canonical],
|
|
],
|
|
];
|
|
|
|
$jsonld = ['@context' => 'https://schema.org', '@graph' => [$article, $breadcrumb]];
|
|
@endphp
|
|
<script type="application/ld+json">{!! json_encode($jsonld, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG | JSON_PRETTY_PRINT) !!}</script>
|