From d82e7cd9194acffbb2ba420138166dfa1c8d13f1 Mon Sep 17 00:00:00 2001 From: Jesse Leite Date: Fri, 21 Aug 2020 17:18:00 -0400 Subject: [PATCH] Generate pages for collection scoped taxonomy terms. --- src/Generator.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/Generator.php b/src/Generator.php index 55d0188..90263b3 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -6,6 +6,7 @@ use Statamic\Support\Str; use Statamic\Facades\Site; use Illuminate\Support\Arr; +use Statamic\Facades\Collection; use Statamic\Facades\Entry; use Statamic\Facades\Term; use League\Flysystem\Adapter\Local; @@ -172,6 +173,7 @@ protected function pages() ->merge($this->urls()) ->merge($this->entries()) ->merge($this->terms()) + ->merge($this->scopedTerms()) ->values() ->reject(function ($page) { return in_array($page->url(), $this->config['exclude']); @@ -194,6 +196,30 @@ protected function terms() })->filter->isGeneratable(); } + protected function scopedTerms() + { + return Collection::all() + ->flatMap(function ($collection) { + return $this->getCollectionTerms($collection); + }) + ->map(function ($content) { + return $this->createPage($content); + }) + ->filter + ->isGeneratable(); + } + + public function getCollectionTerms($collection) + { + return $collection + ->taxonomies() + ->flatMap(function ($taxonomy) { + return $taxonomy->queryTerms()->get(); + }) + ->map + ->collection($collection); + } + protected function urls() { return collect($this->config['urls'] ?? [])->map(function ($url) {