Skip to content

Commit

Permalink
Fix some social images generator bugs (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni authored May 24, 2022
1 parent 7a2843a commit 1f08375
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions resources/stubs/social_images/layout.antlers.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{ mix src='css/tailwind.css' }}">
<style>.phpdebugbar { display: none !important; }</style>
</head>
<body style="width: {{ width }}px; height: {{ height }}px;">
Expand Down
3 changes: 2 additions & 1 deletion src/Actions/ClearImageGlideCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public static function handle(string $path): void

// Get the path of the cached image.
$cachePath = $disk->getFilesRecursively('/')
->firstWhere(fn ($cachePath) => str_contains($cachePath, $path));
->filter(fn ($cachePath) => str_contains($cachePath, $path))
->first();

// Delete the cached image.
if ($cachePath) {
Expand Down
14 changes: 10 additions & 4 deletions src/Fieldtypes/SocialImageFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ public function preload(): array
return $meta;
}

public function augment($value): string
public function augment($value): ?string
{
$parent = $this->field->parent();
$type = $this->config()['image_type'];

$image = SocialImage::all($parent)->get($type);

return $image->exists()
? $image->absoluteUrl()
: $image->generate()->absoluteUrl();
if ($image->exists()) {
return $image->absoluteUrl();
}

if ($parent->generate_social_images) {
return $image->generate()->absoluteUrl();
}

return null;
}
}
9 changes: 8 additions & 1 deletion src/Support/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public static function isBlueprintCpRoute(): bool
*/
public static function isCustomRoute(): bool
{
return request()->route()->getAction('controller') !== 'Statamic\Http\Controllers\FrontendController@index';
$allowedControllerActions = collect([
'Aerni\AdvancedSeo\Http\Controllers\Web\SocialImagesController@show',
'Statamic\Http\Controllers\FrontendController@index',
]);

$controllerAction = request()->route()->getAction('controller');

return $allowedControllerActions->doesntContain($controllerAction);
}
}

0 comments on commit 1f08375

Please sign in to comment.