Skip to content

Commit

Permalink
Including featured image in social image logic
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdancingcat committed Oct 24, 2023
1 parent e67339a commit ad932ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/Repositories/ArticleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public function getSocialImage($article)
];
}

if (!empty($article['featured'])) {
return [
'url' => $article['featured']['url'],
'alt_text' => $article['featured']['alt_text'],
];
}

if (!empty($article['hero_image'])) {
return [
'url' => $article['hero_image']['url'],
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Repositories/ArticleRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public function article_with_hero_should_return_hero_url(): void
{
$article = app(Article::class)->create(1, true, [
'social_image' => null,
'featured' => null,
]);

$imageUrl = app(ArticleRepository::class)->getSocialImage($article['data']);
Expand All @@ -175,6 +176,7 @@ public function article_with_body_image_should_return_url(): void

$article = app(Article::class)->create(1, true, [
'hero_image' => null,
'featured' => null,
'social_image' => null,
'body' => '<img src="'.$url.'" alt="'.$alt.'">',
]);
Expand Down

0 comments on commit ad932ec

Please sign in to comment.