Skip to content

Commit b5da6f5

Browse files
committed
Fix missing SEO Image url exception
1 parent c0917cf commit b5da6f5

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ TODO
215215
- tag controller
216216
- sitemap implementation
217217
- asset manager install in panel
218+
- orm listeners for linkable models that are in a menu to avoid accidental deletion.
219+
- frontend caching for menus
218220

219221
## Changelog
220222

src/Http/Controllers/PageController.php

Lines changed: 18 additions & 15 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\Exceptions\CouldNotLoadImage;
1314
use Spatie\Image\Image;
1415
use Spatie\MediaLibrary\MediaCollections\Models\Media;
1516
use Statikbe\FilamentFlexibleContentBlockPages\Facades\FilamentFlexibleContentBlockPages;
@@ -168,32 +169,34 @@ protected function setSEOImage(Page $page)
168169
}
169170
}
170171

171-
if ($seoUrl && $imageDimensions) {
172+
if ($seoUrl && ! empty($imageDimensions)) {
172173
SEOTools::opengraph()->addImage($seoUrl, $imageDimensions);
173174
SEOTools::twitter()->addValue('image', $seoUrl);
174175
}
175176
}
176177

177178
/**
178179
* Get the dimensions of an image with the given path. Uses cache so the image file does not need to be read each time.
179-
*
180-
* @return array|mixed
181180
*/
182-
protected function getSEOImageDimensions(Media $seoMedia, string $conversion)
181+
protected function getSEOImageDimensions(Media $seoMedia, string $conversion): array
183182
{
184183
$cacheKey = sprintf(self::CACHE_SEO_IMAGE_DIMENSIONS, $seoMedia->uuid);
185184

186-
return Cache::remember($cacheKey,
187-
self::CACHE_SEO_IMAGE_TTL,
188-
function () use ($seoMedia, $conversion) {
189-
$filePath = $seoMedia->getPath($conversion);
190-
$image = Image::load($filePath);
191-
192-
return [
193-
'width' => $image->getWidth(),
194-
'height' => $image->getHeight(),
195-
];
196-
});
185+
try {
186+
return Cache::remember($cacheKey,
187+
self::CACHE_SEO_IMAGE_TTL,
188+
function () use ($seoMedia, $conversion) {
189+
$filePath = $seoMedia->getPath($conversion);
190+
$image = Image::load($filePath);
191+
192+
return [
193+
'width' => $image->getWidth(),
194+
'height' => $image->getHeight(),
195+
];
196+
});
197+
} catch (CouldNotLoadImage $exception) {
198+
return [];
199+
}
197200
}
198201

199202
private function getSettingsTitle(): string

0 commit comments

Comments
 (0)