Skip to content

Commit 1994a7d

Browse files
committed
Fix terms generated by sitemap. Closes #124.
1 parent 62ffe79 commit 1994a7d

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/Sitemap/Sitemap.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ protected function publishedContent()
5252
return collect()
5353
->merge($this->publishedEntries())
5454
->merge($this->publishedTerms())
55+
->merge($this->publishedCollectionTerms())
5556
->values();
5657
}
5758

5859
protected function publishedEntries()
5960
{
6061
return Collection::all()
6162
->flatMap(function ($collection) {
62-
return $collection->cascade('seo') !== false ? $collection->queryEntries()->get() : collect();
63+
return $collection->cascade('seo') !== false
64+
? $collection->queryEntries()->get()
65+
: collect();
6366
})
6467
->filter(function ($entry) {
6568
return $entry->status() === 'published';
@@ -70,9 +73,34 @@ protected function publishedTerms()
7073
{
7174
return Taxonomy::all()
7275
->flatMap(function ($taxonomy) {
73-
return $taxonomy->cascade('seo') !== false ? $taxonomy->queryTerms()->get() : collect();
76+
return $taxonomy->cascade('seo') !== false
77+
? $taxonomy->queryTerms()->get()
78+
: collect();
7479
})
7580
->filter
76-
->published();
81+
->published()
82+
->filter(function ($term) {
83+
return view()->exists($term->template());
84+
});
85+
}
86+
87+
protected function publishedCollectionTerms()
88+
{
89+
return Collection::all()
90+
->flatMap(function ($collection) {
91+
return $collection->cascade('seo') !== false
92+
? $collection->taxonomies()->map->collection($collection)
93+
: collect();
94+
})
95+
->flatMap(function ($taxonomy) {
96+
return $taxonomy->cascade('seo') !== false
97+
? $taxonomy->queryTerms()->get()->map->collection($taxonomy->collection())
98+
: collect();
99+
})
100+
->filter
101+
->published()
102+
->filter(function ($term) {
103+
return view()->exists($term->template());
104+
});
77105
}
78106
}

0 commit comments

Comments
 (0)