Skip to content

Commit

Permalink
Better support for taxonomy inclusion/exclusion
Browse files Browse the repository at this point in the history
Signed-off-by: Marty Friedel <[email protected]>
  • Loading branch information
martyf committed Oct 4, 2021
1 parent bd35776 commit 1eccb6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 9 additions & 5 deletions config/sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
]
];
12 changes: 10 additions & 2 deletions src/Http/Controllers/StatamicXmlSitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down Expand Up @@ -166,6 +174,6 @@ protected function loadCollectionTerms(): \Illuminate\Support\Collection
]);
});
});
})->flatten(1);
})->filter()->flatten(1);
}
}

0 comments on commit 1eccb6f

Please sign in to comment.