Skip to content

Commit

Permalink
Generate pages for collection scoped taxonomy terms.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite committed Aug 21, 2020
1 parent 0997149 commit d82e7cd
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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']);
Expand All @@ -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) {
Expand Down

0 comments on commit d82e7cd

Please sign in to comment.