From 6d2bd8b8ed588aa9da827611fbc9965af9a09dc9 Mon Sep 17 00:00:00 2001 From: Eric Bus Date: Tue, 24 Nov 2026 11:52:59 +0100 Subject: [PATCH] SEO for news overview pages (tag, region, theme, search) - Canonical URL includes ?pagina=N, so later pages aren't treated as duplicates of page 1; 'load more' button links to the next page so search engines can reach older articles (JavaScript still loads in place) - Description per page ('Het laatste nieuws over Blaricum van GOOI&meer...') and '(pagina N)' in the title from page 2 - Real tag name in title/heading ('Gooise Meren' instead of 'Gooise-meren') - CollectionPage + ItemList (articles, numbered across pages) and BreadcrumbList structured data - Open Graph tags (type website, title, description, url, image) - Search results: noindex, follow and no structured data Co-Authored-By: Claude Opus 5.5 --- app/Http/Controllers/NewsController.php | 70 +++++++++++++++++-- resources/views/layouts/_head.blade.php | 10 +-- resources/views/newslist.blade.php | 9 ++- .../views/partial/listing_jsonld.blade.php | 51 ++++++++++++++ 4 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 resources/views/partial/listing_jsonld.blade.php diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php index 85d94302..532c944b 100644 --- a/app/Http/Controllers/NewsController.php +++ b/app/Http/Controllers/NewsController.php @@ -80,17 +80,17 @@ class NewsController extends Controller public function taglist(Request $request, $tag) { - return $this->listNews($request, 'tag/' . $tag, ucfirst($tag)); + return $this->listNews($request, 'tag/' . $tag, ucfirst($tag), 'items', null, $tag); } public function regionlist(Request $request, $region) { - return $this->listNews($request, 'tag/' . $region, ucfirst($region)); + return $this->listNews($request, 'tag/' . $region, ucfirst($region), 'items', null, $region); } public function themelist(Request $request, $theme) { - return $this->listNews($request, 'tag/' . $theme, ucfirst($theme)); + return $this->listNews($request, 'tag/' . $theme, ucfirst($theme), 'items', null, $theme); } public function search(Request $request, $query) @@ -133,7 +133,11 @@ class NewsController extends Controller return abort(); } - private function listNews(Request $request, $url, $title = null, $id = 'items', $total = null) + /** + * @param string|null $slug tag slug of a tag/region/theme page; used to show + * the tag's real name ('Gooise Meren' instead of 'Gooise-meren') + */ + private function listNews(Request $request, $url, $title = null, $id = 'items', $total = null, $slug = null) { if ($request->ajax()) { $total = 5; @@ -147,6 +151,9 @@ class NewsController extends Controller foreach ($apiResult->news ?? [] as $newsItem) { $news[] = new \Model\NewsItem($newsItem); } + if ($slug) { + $title = self::tagTitle($news, $slug) ?: $title; + } $populair = []; if ($title == null) { @@ -176,7 +183,60 @@ class NewsController extends Controller $newsItems[] = new \Model\NewsItem($_newsItem); } - return view($request->ajax() ? ($title == null ? 'partial/home_newslist_small' : 'partial/newslist_small') : ($title == null ? 'news' : 'newslist'), ['populair' => $populair, 'newsItems' => $newsItems, 'podcasts' => $podcasts, 'podcast' => $podcast, 'id' => $id, 'title' => $title, 'news' => $news, 'searchURL' => 'nieuws/zoeken']); + $data = ['populair' => $populair, 'newsItems' => $newsItems, 'podcasts' => $podcasts, 'podcast' => $podcast, 'id' => $id, 'title' => $title, 'news' => $news, 'searchURL' => 'nieuws/zoeken']; + if (!$request->ajax() && $title !== null) { + $data += $this->listingSeo($url, $title, $news, max(1, $page)); + } + + return view($request->ajax() ? ($title == null ? 'partial/home_newslist_small' : 'partial/newslist_small') : ($title == null ? 'news' : 'newslist'), $data); + } + + /** The tag's name as used in the articles, e.g. 'Gooise Meren' for slug 'gooise-meren'. */ + private static function tagTitle(array $news, $slug) + { + foreach ($news as $item) { + foreach ((is_array($item->tags) ? $item->tags : []) as $tag) { + if (($tag->slug ?? null) === $slug && !empty($tag->titel)) { + return $tag->titel; + } + } + } + return null; + } + + /** + * SEO data for news overview pages (tag/region/theme pages and search results): + * canonical URL including the page number, description, Open Graph tags and + * whether to add structured data. Search results are kept out of the index. + */ + private function listingSeo($url, $title, array $news, $page) + { + $isSearch = strpos($url, 'zoeken/') === 0; + $canonical = url()->current() . ($page > 1 ? '?pagina=' . $page : ''); + $description = 'Het laatste nieuws over ' . $title . ' van GOOI&meer, de streekomroep voor Gooi & Vechtstreek.' + . ($page > 1 ? ' Pagina ' . $page . '.' : ''); + + $image = null; + foreach ($news as $item) { + if ($images = $item->imageList()) { + $image = $images[0]['url']; + break; + } + } + + $metadata = (new \Model\MetaData()) + ->set('type', 'website') + ->set('title', $title . ' - Nieuws' . ($page > 1 ? ' (pagina ' . $page . ')' : '')) + ->set('description', $isSearch ? null : $description) + ->set('image', $image); + + return [ + 'canonical' => $canonical, + 'pageNumber' => $page, + 'metadata' => $metadata, + 'noindex' => $isSearch, + 'listingJsonld' => !$isSearch, + ]; } public function popular() diff --git a/resources/views/layouts/_head.blade.php b/resources/views/layouts/_head.blade.php index 170e20e3..8dccd0bb 100644 --- a/resources/views/layouts/_head.blade.php +++ b/resources/views/layouts/_head.blade.php @@ -1,14 +1,16 @@ @include('layouts._analytics') - {!! trim($__env->yieldContent('title')) !!} | GOOI&meer + {!! trim($__env->yieldContent('title')) !!}@if(($pageNumber ?? 1) > 1) (pagina {{ $pageNumber }})@endif | GOOI&meer {{-- Allow large image previews (Google Discover, Top Stories) --}} - - + {{-- Search results are kept out of the index; large image previews for the rest --}} + + {{-- Pages can set $canonical (e.g. overview pages: including ?pagina=N) --}} + @@ -32,7 +34,7 @@ set('url', url()->current()) + $metadata->set('url', $canonical ?? url()->current()) ->prepend('image', $imgBase) ->prepend('audio', route('gemist.fragment')) ->append('title', ' | GOOI&meer') diff --git a/resources/views/newslist.blade.php b/resources/views/newslist.blade.php index 1632fe90..1c311494 100644 --- a/resources/views/newslist.blade.php +++ b/resources/views/newslist.blade.php @@ -9,6 +9,12 @@ @section('page_class') news_post post_container @endsection + +@if(!empty($listingJsonld)) + @push('head') + @include('partial/listing_jsonld', ['title' => $title, 'news' => $news, 'canonical' => $canonical, 'pageNumber' => $pageNumber]) + @endpush +@endif @section('page_container_class') grey_background @endsection @@ -90,7 +96,8 @@ @if(count($news) >= 15)
- LAAD MEER NIEUWSBERICHTEN diff --git a/resources/views/partial/listing_jsonld.blade.php b/resources/views/partial/listing_jsonld.blade.php new file mode 100644 index 00000000..f9f94534 --- /dev/null +++ b/resources/views/partial/listing_jsonld.blade.php @@ -0,0 +1,51 @@ +{{-- + Structured data (schema.org JSON-LD) for a news overview page (tag, region, + theme): a CollectionPage with the articles on this page as an ItemList, and + the breadcrumb. Parameters: $title, $news, $canonical, $pageNumber. +--}} +@php + $home = rtrim(url('/'), '/') . '/'; + $firstPage = strtok($canonical, '?'); + // Position across pages: the articles on page N follow those of the earlier pages + $offset = ($pageNumber - 1) * count($news); + + $items = []; + foreach (array_values($news) as $i => $item) { + $items[] = [ + '@type' => 'ListItem', + 'position' => $offset + $i + 1, + 'url' => url($item->url), + 'name' => $item->plainTitle(), + ]; + } + + $collection = [ + '@type' => 'CollectionPage', + '@id' => $canonical . '#collection', + 'url' => $canonical, + 'name' => $title . ' - Nieuws' . ($pageNumber > 1 ? ' (pagina ' . $pageNumber . ')' : ''), + 'description' => 'Het laatste nieuws over ' . $title . ' van GOOI&meer, de streekomroep voor Gooi & Vechtstreek.', + 'about' => ['@type' => 'Thing', 'name' => $title], + 'inLanguage' => 'nl-NL', + 'isPartOf' => ['@id' => $home . '#website'], + 'publisher' => ['@id' => $home . '#organization'], + 'mainEntity' => [ + '@type' => 'ItemList', + 'itemListOrder' => 'https://schema.org/ItemListOrderDescending', + 'numberOfItems' => count($items), + 'itemListElement' => $items, + ], + ]; + + $breadcrumb = [ + '@type' => 'BreadcrumbList', + 'itemListElement' => [ + ['@type' => 'ListItem', 'position' => 1, 'name' => 'Home', 'item' => $home], + ['@type' => 'ListItem', 'position' => 2, 'name' => 'Nieuws', 'item' => route('nieuws')], + ['@type' => 'ListItem', 'position' => 3, 'name' => $title, 'item' => $firstPage], + ], + ]; + + $jsonld = ['@context' => 'https://schema.org', '@graph' => [$collection, $breadcrumb]]; +@endphp +