diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-94206-AddExcludePagesRecursiveOptionToSitemapGeneration.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-94206-AddExcludePagesRecursiveOptionToSitemapGeneration.rst new file mode 100644 index 0000000000000000000000000000000000000000..c8051223deb0655d96b6a974359d87c7aa125459 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-94206-AddExcludePagesRecursiveOptionToSitemapGeneration.rst @@ -0,0 +1,36 @@ +.. include:: ../../Includes.txt + +============================================================================ +Feature: #94206 - Add excludePagesRecursive option to XML sitemap generation +============================================================================ + +See :issue:`94206` + +Description +=========== + +With this option you can exclude pages recursively in the XML sitemap: + +.. code-block:: typoscript + + plugin.tx_seo { + config { + xmlSitemap { + sitemaps { + pages { + config { + # comma-separated list of page uids which should be excluded recursive + excludePagesRecursive = 2,3 + } + } + } + } + } + } + +Impact +====== + +The new option enables integrators to easily exclude pages recursively in the XML sitemap + +.. index:: ext:seo diff --git a/typo3/sysext/seo/Classes/XmlSitemap/PagesXmlSitemapDataProvider.php b/typo3/sysext/seo/Classes/XmlSitemap/PagesXmlSitemapDataProvider.php index 8ee0b6e8171602404339a552e66d941779815c2b..f66518ffb34252bb841b8e523d3a55447c2a36de 100644 --- a/typo3/sysext/seo/Classes/XmlSitemap/PagesXmlSitemapDataProvider.php +++ b/typo3/sysext/seo/Classes/XmlSitemap/PagesXmlSitemapDataProvider.php @@ -70,8 +70,14 @@ class PagesXmlSitemapDataProvider extends AbstractXmlSitemapDataProvider $rootPageId = $site->getRootPageId(); } + $excludePagesRecursive = GeneralUtility::intExplode(',', $this->config['excludePagesRecursive'] ?? '', true); + $excludePagesRecursiveWhereClause = ''; + if ($excludePagesRecursive !== []) { + $excludePagesRecursiveWhereClause = sprintf('uid NOT IN (%s)', implode(',', $excludePagesRecursive)); + } + $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); - $treeList = $cObj->getTreeList(-$rootPageId, 99); + $treeList = $cObj->getTreeList(-$rootPageId, 99, 0, false, '', $excludePagesRecursiveWhereClause); $treeListArray = GeneralUtility::intExplode(',', $treeList); $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) diff --git a/typo3/sysext/seo/Configuration/TypoScript/XmlSitemap/constants.typoscript b/typo3/sysext/seo/Configuration/TypoScript/XmlSitemap/constants.typoscript index 111ec7a6ba8ce2d3b65908e5d3a1910af61de7f2..fabd73a8f9f4969bca1ac0da837c2ba90153c01c 100644 --- a/typo3/sysext/seo/Configuration/TypoScript/XmlSitemap/constants.typoscript +++ b/typo3/sysext/seo/Configuration/TypoScript/XmlSitemap/constants.typoscript @@ -16,6 +16,8 @@ plugin.tx_seo { pages { # cat=plugin.tx_seo/sitemap; type=string; label=Doktypes to exclude excludedDoktypes = 3, 4, 6, 7, 199, 254, 255 + # cat=plugin.tx_seo/sitemap; type=string; label=List of page uids which should be excluded recursive + excludePagesRecursive = # cat=plugin.tx_seo/sitemap; type=string; label=Additional where clause additionalWhere = no_index = 0 AND canonical_link = '' } diff --git a/typo3/sysext/seo/Configuration/TypoScript/XmlSitemap/setup.typoscript b/typo3/sysext/seo/Configuration/TypoScript/XmlSitemap/setup.typoscript index 238c1f5bed63c89942d251acd0f5bf864a9cb8ae..12168fc454760ea05d0fc0e647dd3d6638c31243 100644 --- a/typo3/sysext/seo/Configuration/TypoScript/XmlSitemap/setup.typoscript +++ b/typo3/sysext/seo/Configuration/TypoScript/XmlSitemap/setup.typoscript @@ -48,6 +48,8 @@ plugin.tx_seo { # Here you can override the xslFile for a single sitemap # xslFile = EXT:seo/Resources/Public/CSS/Sitemap.xsl excludedDoktypes = {$plugin.tx_seo.settings.xmlSitemap.sitemaps.pages.excludedDoktypes} + # comma-separated list of page uids which should be excluded recursive + excludePagesRecursive = {$plugin.tx_seo.settings.xmlSitemap.sitemaps.pages.excludePagesRecursive} additionalWhere = {$plugin.tx_seo.settings.xmlSitemap.sitemaps.pages.additionalWhere} } } diff --git a/typo3/sysext/seo/Tests/Functional/Fixtures/excludePagesRecursive.typoscript b/typo3/sysext/seo/Tests/Functional/Fixtures/excludePagesRecursive.typoscript new file mode 100644 index 0000000000000000000000000000000000000000..cd6b2cb394c272d8ebeaaf56998b83572065bd5c --- /dev/null +++ b/typo3/sysext/seo/Tests/Functional/Fixtures/excludePagesRecursive.typoscript @@ -0,0 +1,11 @@ +plugin.tx_seo { + settings { + xmlSitemap { + sitemaps { + pages { + excludePagesRecursive = 2 + } + } + } + } +} diff --git a/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesTest.php b/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesTest.php index b5d0fc79304d20a9abb13e4652aed70e8614b1de..60c4cc4157960e9680f9d58f42784eed92505d45 100644 --- a/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesTest.php +++ b/typo3/sysext/seo/Tests/Functional/XmlSitemap/XmlSitemapPagesTest.php @@ -134,4 +134,45 @@ class XmlSitemapPagesTest extends AbstractXmlSitemapPagesTest (string)$this->getResponse('http://localhost/de/')->getBody() ); } + + /** + * @test + */ + public function pagesSitemapDoesNotContainUrlsOfExcludedPages(): void + { + $this->setUpFrontendRootPage( + 1, + [ + 'constants' => [ + 'EXT:seo/Configuration/TypoScript/XmlSitemap/constants.typoscript', + 'EXT:seo/Tests/Functional/Fixtures/excludePagesRecursive.typoscript' + ], + 'setup' => ['EXT:seo/Configuration/TypoScript/XmlSitemap/setup.typoscript'] + ] + ); + + $xml = (string)$this->getResponse()->getBody(); + self::assertStringNotContainsString( + '<loc>http://localhost/dummy-1-2</loc>', + $xml + ); + self::assertStringNotContainsString( + '<loc>http://localhost/dummy-1-2-5</loc>', + $xml + ); + self::assertStringNotContainsString( + '<loc>http://localhost/dummy-1-2-6</loc>', + $xml + ); + + self::assertStringContainsString( + '<loc>http://localhost/</loc>', + $xml + ); + + self::assertStringContainsString( + '<loc>http://localhost/dummy-1-3</loc>', + $xml + ); + } }