Skip to content

Commit 1632708

Browse files
committed
improve SEO fields
1 parent 9071421 commit 1632708

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

resources/views/components/layouts/base.blade.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<meta name="csrf-token" content="{{ csrf_token() }}">
77

8-
<title>{{ $title }}</title>
9-
10-
{!! \Artesaos\SEOTools\SEOTools::generate() !!}
8+
{!! \Artesaos\SEOTools\Facades\SEOTools::generate() !!}
119

1210
<!-- Scripts -->
1311
@vite(['resources/css/app.css', 'resources/js/app.js'])

resources/views/pages/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* @var Page $page */
66
@endphp
77

8-
<x-flexible-pages-base-layout title="{{ $page->title }}" wide="true">
8+
<x-flexible-pages-base-layout wide="true">
99
<header>
1010
<x-flexible-pages-language-switch/>
1111
</header>

src/Components/BaseLayout.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
class BaseLayout extends Component
88
{
9-
public function __construct(public string $title){}
10-
119
public function render()
1210
{
1311
return view('filament-flexible-content-block-pages::components.layouts.base');

src/Http/Controllers/PageController.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Support\Facades\Auth;
1111
use Illuminate\Support\Facades\Cache;
1212
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
13+
use Spatie\Image\Image;
1314
use Spatie\MediaLibrary\Conversions\ConversionCollection;
1415
use Spatie\MediaLibrary\MediaCollections\Models\Media;
1516
use Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages;
@@ -41,13 +42,8 @@ public function index(Page $page)
4142
$this->setSEOLocalisationAndCanonicalUrl();
4243
$this->setSEOImage($page);
4344

44-
$title = $page->title ??
45-
SEOTools::getTitle() ??
46-
$this->getSettingsTitle();
47-
4845
return view(self::TEMPLATE_PATH, [
4946
'page' => $page,
50-
'title' => $title,
5147
]);
5248
}
5349

@@ -81,8 +77,12 @@ public function grandchildIndex(Page $grandparent, Page $parent, Page $page)
8177
return $this->index($page);
8278
}
8379

84-
protected function getSEOTitlePostfix()
80+
protected function getSEOTitlePostfix(Page $page): string
8581
{
82+
if($page->isHomePage()) {
83+
return '';
84+
}
85+
8686
return sprintf(' | %s', flexiblePagesSetting(Settings::SETTING_SITE_TITLE));
8787
}
8888

@@ -126,7 +126,8 @@ protected function getLocalisedUrls(): array
126126

127127
protected function setBasicSEO(Page $page)
128128
{
129-
SEOTools::setTitle(($page->seo_title ?? $page->title ?? $this->getSettingsTitle()).$this->getSEOTitlePostfix());
129+
$title = $page->seo_title ?? $page->title ?? $this->getSettingsTitle();
130+
SEOTools::setTitle($title . $this->getSEOTitlePostfix($page), false);
130131
SEOTools::setDescription(($page->seo_description ?? strip_tags($page->intro)));
131132
SEOTools::opengraph()->setUrl(url()->current());
132133
}
@@ -177,12 +178,12 @@ protected function getSEOImageDimensions(Media $seoMedia, string $conversion)
177178
return Cache::remember($cacheKey,
178179
self::CACHE_SEO_IMAGE_TTL,
179180
function () use ($seoMedia, $conversion) {
180-
$conversionCollection = ConversionCollection::createForMedia($seoMedia);
181-
$conversion = $conversionCollection->getByName($conversion);
181+
$filePath = $seoMedia->getPath($conversion);
182+
$image = Image::load($filePath);
182183

183184
return [
184-
'width' => $conversion->getWidth(),
185-
'height' => $conversion->getHeight(),
185+
'width' => $image->getWidth(),
186+
'height' => $image->getHeight(),
186187
];
187188
});
188189
}

src/Models/Page.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ public static function getUrl(string $code, ?string $locale = null): ?string
6767
->first()
6868
?->getViewUrl($locale);
6969
}
70+
71+
public function isHomePage(): bool
72+
{
73+
return $this->code === static::HOME_PAGE;
74+
}
7075
}

src/Routes/LocalisedPageRouteHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function defineRoutes(): void
2323

2424
public function getUrl(Page $page, ?string $locale = null): string
2525
{
26-
if ($page->code === Page::HOME_PAGE) {
26+
if ($page->isHomePage()) {
2727
return LaravelLocalization::getLocalizedUrl($locale, static::ROUTE_HOME);
2828
}
2929

src/Routes/PageRouteHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class PageRouteHelper extends AbstractPageRouteHelper
1111
{
1212
public function getUrl(Page $page, ?string $locale = null): string
1313
{
14-
if ($page->code === Page::HOME_PAGE) {
14+
if ($page->isHomePage()) {
1515
return route(static::ROUTE_HOME);
1616
}
1717

0 commit comments

Comments
 (0)