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 <noreply@anthropic.com>
This commit is contained in:
1 parent
f7b1dbac8f
commit
6d2bd8b8ed
4 files changed
+130
-10
No files matched your search
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user