44
55use Illuminate \Support \Collection as IlluminateCollection ;
66use Illuminate \Support \LazyCollection ;
7+ use Illuminate \Support \Str ;
78use Statamic \Contracts \Entries \Entry ;
89use Statamic \Contracts \Query \Builder ;
910use Statamic \Contracts \Taxonomies \Term ;
@@ -24,13 +25,6 @@ class Sitemap
2425
2526 const CACHE_KEY = 'seo-pro.sitemap ' ;
2627
27- private IlluminateCollection $ sites ;
28-
29- public function __construct ()
30- {
31- $ this ->sites = collect ();
32- }
33-
3428 public function pages (): array
3529 {
3630 return collect ()
@@ -103,11 +97,11 @@ public function paginatedSitemaps(): array
10397 ->all ();
10498 }
10599
106- public function forSites ( IlluminateCollection $ sites ): self
100+ private function sites ( ): IlluminateCollection
107101 {
108- $ this -> sites = $ sites ;
102+ $ sites = SiteFacade:: all ()-> filter ( fn ( $ site ) => Str:: of ( $ site -> absoluteUrl ())-> startsWith ( request ()-> schemeAndHttpHost ())) ;
109103
110- return $ this ;
104+ return $ this -> runHooks ( ' sites ' , $ sites ) ;
111105 }
112106
113107 protected function getPages ($ items )
@@ -153,8 +147,8 @@ protected function publishedEntriesQuery()
153147
154148 return EntryFacade::query ()
155149 ->when (
156- $ this ->sites ->isNotEmpty (),
157- fn (Builder $ query ) => $ query ->whereIn ('site ' , $ this ->sites ->map ->handle ()->all ())
150+ $ this ->sites () ->isNotEmpty (),
151+ fn (Builder $ query ) => $ query ->whereIn ('site ' , $ this ->sites () ->map ->handle ()->all ())
158152 )
159153 ->whereIn ('collection ' , $ collections )
160154 ->whereNotNull ('uri ' )
@@ -190,7 +184,7 @@ protected function publishedTerms()
190184 return $ taxonomy ->cascade ('seo ' ) !== false
191185 ? $ taxonomy
192186 ->queryTerms ()
193- ->when ($ this ->sites ->isNotEmpty (), fn (Builder $ query ) => $ query ->whereIn ('site ' , $ this ->sites ->map ->handle ()->all ()))
187+ ->when ($ this ->sites () ->isNotEmpty (), fn (Builder $ query ) => $ query ->whereIn ('site ' , $ this ->sites () ->map ->handle ()->all ()))
194188 ->get ()
195189 : collect ();
196190 })
@@ -213,7 +207,7 @@ protected function publishedCollectionTerms()
213207 return $ taxonomy ->cascade ('seo ' ) !== false
214208 ? $ taxonomy
215209 ->queryTerms ()
216- ->when ($ this ->sites ->isNotEmpty (), fn (Builder $ query ) => $ query ->whereIn ('site ' , $ this ->sites ->map ->handle ()->all ()))
210+ ->when ($ this ->sites () ->isNotEmpty (), fn (Builder $ query ) => $ query ->whereIn ('site ' , $ this ->sites () ->map ->handle ()->all ()))
217211 ->get ()->map ->collection ($ taxonomy ->collection ())
218212 : collect ();
219213 })
0 commit comments