|
11 | 11 | use Illuminate\Support\Facades\Cache; |
12 | 12 | use Mcamara\LaravelLocalization\Facades\LaravelLocalization; |
13 | 13 | use Spatie\Image\Image; |
14 | | -use Spatie\MediaLibrary\Conversions\ConversionCollection; |
15 | 14 | use Spatie\MediaLibrary\MediaCollections\Models\Media; |
16 | 15 | use Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages; |
17 | 16 | use Statikbe\FilamentFlexibleContentBlockPages\Models\Page; |
@@ -79,7 +78,7 @@ public function grandchildIndex(Page $grandparent, Page $parent, Page $page) |
79 | 78 |
|
80 | 79 | protected function getSEOTitlePostfix(Page $page): string |
81 | 80 | { |
82 | | - if($page->isHomePage()) { |
| 81 | + if ($page->isHomePage()) { |
83 | 82 | return ''; |
84 | 83 | } |
85 | 84 |
|
@@ -126,8 +125,8 @@ protected function getLocalisedUrls(): array |
126 | 125 |
|
127 | 126 | protected function setBasicSEO(Page $page) |
128 | 127 | { |
129 | | - $title = $page->seo_title ?? $page->title ?? $this->getSettingsTitle(); |
130 | | - SEOTools::setTitle($title . $this->getSEOTitlePostfix($page), false); |
| 128 | + $title = $this->getValidTitle($page->seo_title) ?? $this->getValidTitle($page->title) ?? $this->getSettingsTitle(); |
| 129 | + SEOTools::setTitle($title.$this->getSEOTitlePostfix($page), false); |
131 | 130 | SEOTools::setDescription(($page->seo_description ?? strip_tags($page->intro))); |
132 | 131 | SEOTools::opengraph()->setUrl(url()->current()); |
133 | 132 | } |
@@ -192,4 +191,17 @@ private function getSettingsTitle(): string |
192 | 191 | { |
193 | 192 | return flexiblePagesSetting(Settings::SETTING_SITE_TITLE, app()->getLocale(), config('app.name')); |
194 | 193 | } |
| 194 | + |
| 195 | + private function getValidTitle(?string $title): ?string |
| 196 | + { |
| 197 | + if (! $title) { |
| 198 | + return null; |
| 199 | + } |
| 200 | + |
| 201 | + if (empty(trim($title))) { |
| 202 | + return null; |
| 203 | + } |
| 204 | + |
| 205 | + return $title ? trim($title) : null; |
| 206 | + } |
195 | 207 | } |
0 commit comments