Skip to content

Commit 21c940d

Browse files
authored
[image] use lowercased filename (#2777)
* bump deps * lowercased filepath * make path lowercased to avoid surprisees
1 parent c370fbf commit 21c940d

5 files changed

Lines changed: 69 additions & 62 deletions

File tree

composer.lock

Lines changed: 56 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/blog/post.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<meta property="og:type" content="article"/>
1111
<meta
1212
property="og:image"
13-
content="{{ action(\App\Controller\Socials\PostThumbnailController::class, ['title' => $post->getClearTitle()]) }}?v=3"
13+
content="{{ action(\App\Controller\Socials\PostThumbnailController::class, ['title' => $post->getClearTitleLowercased()]) }}?v=3"
1414
/>
1515

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

src/Controller/Socials/PostThumbnailController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public function __construct(
2323
) {
2424
}
2525

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

3030
// on the fly
3131
if (! file_exists($imageFilePath)) {
32-
$this->createImage($title, $imageFilePath);
32+
$this->createImage($lowercasedTitle, $imageFilePath);
3333
}
3434

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

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

49-
$post = $this->postRepository->findByTitle($title);
49+
$post = $this->postRepository->findByLowercasedTitle($title);
5050
if (! $post instanceof Post) {
5151
return;
5252
}

src/Entity/Post.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public function getClearTitle(): string
4242
return str_replace('?', '', $clearTitle);
4343
}
4444

45+
public function getClearTitleLowercased(): string
46+
{
47+
return strtolower($this->getClearTitle());
48+
}
49+
4550
public function getPerex(): string
4651
{
4752
return $this->perex;

src/Repository/PostRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ public function getPosts(): array
3636
return $this->posts;
3737
}
3838

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

0 commit comments

Comments
 (0)