News: Canonical auf Success Story (Feld vitec_canonical_usecase), 13 Paare gesetzt
13 Pressemeldungen tragen denselben Text wie eine Success Story (Seobility: doppelter Inhalt). Neues Feld am News-Datensatz (Tab 'VITEC SEO', Auswahl der Story); VitecMetaHandler ersetzt damit den Canonical-Link durch /success-stories/<slug>. Die Meldung bleibt in der Liste, Suchmaschinen werten die Story als Original. Migration news_story_canonical_20261110 setzt die 13 Zuordnungen (angewendet). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
f7b1eacecb
commit
4b6731786d
4 files changed
+135
No files matched your search
@@ -67,6 +67,7 @@ class VitecMetaHandler extends MetaHandler
|
||||
$title = trim((string)($content['seo']['title'] ?? ''));
|
||||
$description = '';
|
||||
$image = '';
|
||||
$canonicalPath = '';
|
||||
|
||||
// --- record context -------------------------------------------------
|
||||
$newsUid = (int)($args['tx_news_pi1']['news'] ?? 0);
|
||||
@@ -90,6 +91,15 @@ class VitecMetaHandler extends MetaHandler
|
||||
);
|
||||
}
|
||||
$image = $this->firstImage('tx_news_domain_model_news', 'fal_media', $newsUid);
|
||||
// Same text as a success story: the story is the original.
|
||||
$storyUid = (int)($news['vitec_canonical_usecase'] ?? 0);
|
||||
if ($storyUid > 0) {
|
||||
$story = $this->fetchRow('tx_vitec_domain_model_usecase', ['uid' => $storyUid]);
|
||||
$storySlug = trim((string)($story['slug'] ?? ''));
|
||||
if ($storySlug !== '') {
|
||||
$canonicalPath = '/success-stories/' . $storySlug;
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($productArg !== '') {
|
||||
$product = is_numeric($productArg)
|
||||
@@ -227,6 +237,23 @@ class VitecMetaHandler extends MetaHandler
|
||||
}
|
||||
}
|
||||
|
||||
// --- news article whose canonical is a success story --------------------
|
||||
if ($canonicalPath !== '') {
|
||||
$href = $this->absolute($canonicalPath, $base);
|
||||
$links = is_array($content['seo']['link'] ?? null) ? $content['seo']['link'] : [];
|
||||
$replaced = false;
|
||||
foreach ($links as $index => $link) {
|
||||
if (($link['rel'] ?? '') === 'canonical') {
|
||||
$links[$index]['href'] = $href;
|
||||
$replaced = true;
|
||||
}
|
||||
}
|
||||
if (!$replaced) {
|
||||
$links[] = ['href' => $href, 'rel' => 'canonical'];
|
||||
}
|
||||
$content['seo']['link'] = $links;
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
defined('TYPO3') or die();
|
||||
|
||||
// Canonical story for a news article: when a success story carries the same
|
||||
// text as the article, the article stays in the news list but its canonical
|
||||
// link points to the story (VitecMetaHandler reads this field).
|
||||
(static function (): void {
|
||||
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_news_domain_model_news', [
|
||||
'vitec_canonical_usecase' => [
|
||||
'label' => 'Canonical success story',
|
||||
'description' => 'Set when a success story carries the same text as this article. The article stays in the news list; search engines count the story as the original.',
|
||||
'config' => [
|
||||
'type' => 'select',
|
||||
'renderType' => 'selectSingle',
|
||||
'foreign_table' => 'tx_vitec_domain_model_usecase',
|
||||
'foreign_table_where' => 'AND {#tx_vitec_domain_model_usecase}.{#deleted} = 0 ORDER BY tx_vitec_domain_model_usecase.title',
|
||||
'items' => [['label' => '— none —', 'value' => 0]],
|
||||
'default' => 0,
|
||||
'size' => 1,
|
||||
'maxitems' => 1,
|
||||
],
|
||||
],
|
||||
]);
|
||||
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
|
||||
'tx_news_domain_model_news',
|
||||
'--div--;VITEC SEO, vitec_canonical_usecase'
|
||||
);
|
||||
})();
|
||||
@@ -518,3 +518,7 @@ CREATE TABLE tx_vitec_clienterrorlog (
|
||||
PRIMARY KEY (uid),
|
||||
KEY crdate (crdate)
|
||||
);
|
||||
|
||||
CREATE TABLE tx_news_domain_model_news (
|
||||
vitec_canonical_usecase int(11) unsigned DEFAULT '0' NOT NULL
|
||||
);
|
||||
Reference in new issue
Block a user