diff --git a/config/sitemap.php b/config/sitemap.php index 5b9876b..8b23645 100644 --- a/config/sitemap.php +++ b/config/sitemap.php @@ -24,19 +24,23 @@ | Set "include" to true to either include or exclude without explicitly setting per article | Frequency and Priority are standard for an XML sitemap | + | 'includeTaxonomies' enables (or disables) whether taxonomy URLs will be generated, if used, + | for the collection. Only applies to Collections that actually use Taxonomies. + | */ 'defaults' => [ - 'blog' => [ + /*'blog' => [ 'include' => true, 'frequency' => 'weekly', 'priority' => '0.7' - ], + ],*/ 'pages' => [ - 'include' => true, - 'frequency' => 'yearly', - 'priority' => '0.5' + 'include' => true, + 'frequency' => 'yearly', + 'priority' => '0.5', + 'includeTaxonomies' => true, ] ] ]; \ No newline at end of file diff --git a/src/Http/Controllers/StatamicXmlSitemapController.php b/src/Http/Controllers/StatamicXmlSitemapController.php index 17519a7..87a91e9 100644 --- a/src/Http/Controllers/StatamicXmlSitemapController.php +++ b/src/Http/Controllers/StatamicXmlSitemapController.php @@ -111,8 +111,16 @@ protected function loadEntries(): \Illuminate\Support\Collection */ protected function loadCollectionTerms(): \Illuminate\Support\Collection { - return collect(array_keys(config('statamic.sitemap.defaults')))->map(function ($handle) { + return collect(config('statamic.sitemap.defaults'))->map(function ($properties, $handle) { + + // if there is a property called includeTaxonomies, and its false (or the collection is disabled) then exclude it + // this has been added for backwards compatibility + if (isset($properties['includeTaxonomies']) && (!$properties['includeTaxonomies'] || !$properties['include'])) { + return false; + } + $collection = Collection::findByHandle($handle); + return $collection->taxonomies()->map->collection($collection)->flatMap(function ( $taxonomy ) { @@ -166,6 +174,6 @@ protected function loadCollectionTerms(): \Illuminate\Support\Collection ]); }); }); - })->flatten(1); + })->filter()->flatten(1); } }