Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 56 additions & 54 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions resources/views/blog/post.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<meta property="og:type" content="article"/>
<meta
property="og:image"
content="{{ action(\App\Controller\Socials\PostThumbnailController::class, ['title' => $post->getClearTitle()]) }}?v=3"
content="{{ action(\App\Controller\Socials\PostThumbnailController::class, ['title' => $post->getClearTitleLowercased()]) }}?v=3"
/>

<meta
Expand All @@ -22,7 +22,7 @@
<meta name="twitter:title" content="{{ $post->getClearTitle() }}"/>
<meta
name="twitter:image"
content="{{ action(\App\Controller\Socials\PostThumbnailController::class, ['title' => $post->getClearTitle()]) }}"
content="{{ action(\App\Controller\Socials\PostThumbnailController::class, ['title' => $post->getClearTitleLowercased()]) }}?v=3"
/>
<meta name="twitter:description" content="{{ $post->getPerex() }}"/>

Expand Down
8 changes: 4 additions & 4 deletions src/Controller/Socials/PostThumbnailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public function __construct(
) {
}

public function __invoke(string $title): BinaryFileResponse
public function __invoke(string $lowercasedTitle): BinaryFileResponse
{
$imageFilePath = $this->thumbnailGenerator->resolveImageFilePath($title);
$imageFilePath = $this->thumbnailGenerator->resolveImageFilePath($lowercasedTitle);

// on the fly
if (! file_exists($imageFilePath)) {
$this->createImage($title, $imageFilePath);
$this->createImage($lowercasedTitle, $imageFilePath);
}

return response()->file($imageFilePath);
Expand All @@ -46,7 +46,7 @@ private function createImage(string $title, string $imageFilePath): void

$greenFont = $this->thumbnailGenerator->createFont(FontFile::INTER, '59a35e', 40);

$post = $this->postRepository->findByTitle($title);
$post = $this->postRepository->findByLowercasedTitle($title);
if (! $post instanceof Post) {
return;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function getClearTitle(): string
return str_replace('?', '', $clearTitle);
}

public function getClearTitleLowercased(): string
{
return strtolower($this->getClearTitle());
}

public function getPerex(): string
{
return $this->perex;
Expand Down
4 changes: 2 additions & 2 deletions src/Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public function getPosts(): array
return $this->posts;
}

public function findByTitle(string $title): ?Post
public function findByLowercasedTitle(string $lowercasedTitle): ?Post
{
$filter = static fn (Post $post): bool => $post->getTitle() === $title;
$filter = static fn (Post $post): bool => strtolower($post->getTitle()) === $lowercasedTitle;
return ArrayLookupFinder::first($this->posts, $filter);
}

Expand Down
Loading