13
13
use Statikbe \FilamentFlexibleContentBlockPages \Facades \FilamentFlexibleContentBlockPages ;
14
14
use Statikbe \FilamentFlexibleContentBlockPages \Models \Page ;
15
15
use Statikbe \FilamentFlexibleContentBlockPages \Services \Enum \SitemapGeneratorMethod ;
16
+ use Statikbe \FilamentFlexibleContentBlocks \ContentBlocks \CallToActionBlock ;
16
17
use Statikbe \FilamentFlexibleContentBlocks \FilamentFlexibleBlocksConfig ;
17
18
use Statikbe \FilamentFlexibleContentBlocks \Models \Contracts \HasCode ;
18
19
use Statikbe \FilamentFlexibleContentBlocks \Models \Contracts \HasParent ;
@@ -95,8 +96,10 @@ protected function addPageToSitemap(Page $page): void
95
96
// Get canonical URL
96
97
$ canonicalUrl = $ page ->getViewUrl ($ this ->canonicalLocale );
97
98
99
+ $ lastModified = $ page ->{$ page ->getUpdatedAtColumn ()} ?? $ page ->{$ page ->getCreatedAtColumn ()};
100
+
98
101
$ urlTag = $ this ->addToSitemap ($ canonicalUrl ,
99
- $ page -> updated_at ?? $ page -> created_at ,
102
+ $ lastModified ,
100
103
$ this ->calculatePriority ($ page ),
101
104
$ this ->calculateChangeFrequency ($ page ),
102
105
onlyCreate: true );
@@ -183,8 +186,7 @@ protected function addCustomUrls(): void
183
186
184
187
protected function getLinkableModels (): array
185
188
{
186
- // 'general' is just random block to trigger fetching the default configuration:
187
- $ ctaModels = FilamentFlexibleBlocksConfig::getCallToActionModels ('general ' );
189
+ $ ctaModels = FilamentFlexibleBlocksConfig::getCallToActionModels (CallToActionBlock::class);
188
190
$ menuModels = FilamentFlexibleContentBlockPages::config ()->getMenuLinkableModels ();
189
191
190
192
// Merge and remove duplicates
@@ -194,12 +196,12 @@ protected function getLinkableModels(): array
194
196
protected function calculatePriority (HasParent &HasCode $ page ): float
195
197
{
196
198
// Homepage gets highest priority
197
- if ($ page ->code === Page::HOME_PAGE ) {
199
+ if (property_exists ( $ page , ' code ' ) && $ page ->code === Page::HOME_PAGE ) {
198
200
return 1.0 ;
199
201
}
200
202
201
203
// Parent pages get higher priority than children
202
- if (! $ page ->parent_id ) {
204
+ if (property_exists ( $ page , ' parent_id ' ) && ! $ page ->parent_id ) {
203
205
return 0.8 ;
204
206
}
205
207
@@ -209,7 +211,8 @@ protected function calculatePriority(HasParent&HasCode $page): float
209
211
210
212
protected function calculateChangeFrequency (Model $ page ): string
211
213
{
212
- $ daysSinceUpdate = $ page ->updated_at ? $ page ->updated_at ->diffInDays (Carbon::now ()) : 365 ;
214
+ $ updatedAt = $ page ->{$ page ->getUpdatedAtColumn ()};
215
+ $ daysSinceUpdate = $ updatedAt ? $ updatedAt ->diffInDays (Carbon::now ()) : 365 ;
213
216
214
217
if ($ daysSinceUpdate < 7 ) {
215
218
return Url::CHANGE_FREQUENCY_WEEKLY ;
0 commit comments