From dd11db7b257326421c910f39cb60bb9ddc4b96e1 Mon Sep 17 00:00:00 2001 From: Jiordi Viera Date: Sat, 26 Oct 2024 06:47:38 +0100 Subject: [PATCH] =?UTF-8?q?Correction=20de=20l'incrementation=20des=20vues?= =?UTF-8?q?=20d'un=20post=20=C3=A0=20l'actualisation=20de=20la=20page,=20e?= =?UTF-8?q?t=20aussi=20ajout=20d'une=20image=20de=20secours=20lorsque=20l'?= =?UTF-8?q?image=20est=20inexistant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ArticlesController.php | 6 +- app/Traits/HasUsername.php | 2 +- resources/views/articles/show.blade.php | 147 +++++++++++++------- 3 files changed, 98 insertions(+), 57 deletions(-) diff --git a/app/Http/Controllers/ArticlesController.php b/app/Http/Controllers/ArticlesController.php index 7b2c0dc5..ca2115fa 100644 --- a/app/Http/Controllers/ArticlesController.php +++ b/app/Http/Controllers/ArticlesController.php @@ -28,13 +28,15 @@ public function show(Article $article): View /** @var User $user */ $user = Auth::user(); - views($article)->record(); + views($article)->cooldown(now()->addHours(2))->record(); /** @var Article $article */ $article = Cache::remember('post-'.$article->id, now()->addHour(), fn () => $article); abort_unless( - $article->isPublished() || ($user && $article->isAuthoredBy($user)) || ($user && $user->hasAnyRole(['admin', 'moderator'])), // @phpstan-ignore-line + $article->isPublished() || ($user && $article->isAuthoredBy($user)) || ($user && $user->hasAnyRole([ + 'admin', 'moderator', + ])), // @phpstan-ignore-line 404 ); diff --git a/app/Traits/HasUsername.php b/app/Traits/HasUsername.php index a75e473a..92ff4d9e 100644 --- a/app/Traits/HasUsername.php +++ b/app/Traits/HasUsername.php @@ -36,7 +36,7 @@ private function generateUniqueUsername(string $value): string return $username; } - private function usernameExists(string $username, ?int $ignoreId = null): bool + private function usernameExists(string $username, int $ignoreId = null): bool { $query = $this->where('username', $username); diff --git a/resources/views/articles/show.blade.php b/resources/views/articles/show.blade.php index b6d45894..882f7417 100644 --- a/resources/views/articles/show.blade.php +++ b/resources/views/articles/show.blade.php @@ -8,6 +8,11 @@ $next = $article->nextArticle(); $previous = $article->previousArticle(); $user = $article->user; + function getAvatar($title): string + { + return 'https://ui-avatars.com/api/?name=' . urlencode($title) + . '&background=random&bold=true&format=svg&size=512'; + } @endphp
@@ -15,13 +20,13 @@

- {{ __('A propos de l’auteur') }} + {{ __('À propos de l’auteur') }}

- +

@@ -39,21 +44,24 @@

@if($user->twitter()) - + Twitter @endif @if($user->linkedin()) - + LinkedIn @endif @if($user->githubUsername()) - + GitHub @@ -67,9 +75,12 @@
@if($next)
-

Article suivant

+

Article + suivant

- {{ $next->slug }} + {{ $next->slug }} {{ $next->title }}
@@ -77,9 +88,13 @@ @if($previous) @@ -88,7 +103,7 @@ @endif
- +
@@ -99,15 +114,16 @@ @if ($article->tags->isNotEmpty())
@foreach ($article->tags as $tag) - + @endforeach
@endif - +
- + {{ __(':time min de lecture', ['time' => $article->readTime()]) }} @@ -120,7 +136,9 @@
- {{ $article->user->username }} + {{ $article->user->username }}

@@ -136,14 +154,15 @@ @if($media = $article->getFirstMediaUrl('media'))

- {{ $article->title }} + {{ $article->title }}
@endif
@@ -151,7 +170,8 @@ class="mt-8 prose prose-lg prose-green text-skin-base mx-auto overflow-x-hidden
- {{ $user->username }} + {{ $user->username }}

@@ -169,21 +189,24 @@ class="mt-8 prose prose-lg prose-green text-skin-base mx-auto overflow-x-hidden

@if($user->twitter()) - + {{ __('Twitter') }} @endif @if($user->linkedin()) - + {{ __('LinkedIn') }} @endif @if($user->githubUsername()) - + {{ __('GitHub') }} @@ -200,17 +223,17 @@ class="mt-8 prose prose-lg prose-green text-skin-base mx-auto overflow-x-hidden @@ -223,21 +246,26 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha
- + {{ __('Éditer') }} - + @if($article->isNotApproved()) @hasanyrole('admin|moderator') - @endhasanyrole @endif -
@@ -251,9 +279,13 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha

{{ __('Article suivant') }}

- {{ $next->slug }} + {{
+                                    $next->slug }}
- {{ $next->title }} + {{ $next->title }} {{ __(':time min de lecture', ['time' => $next->readTime()]) }}
@@ -264,9 +296,13 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha

{{ __('Article précédent') }}

- {{ $previous->slug }} + {{ $previous->slug }}
- {{ $previous->title }} + {{ $previous->title }} {{ __(':time min de lecture', ['time' => $previous->readTime()]) }}
@@ -278,7 +314,7 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha
@@ -297,26 +333,26 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha @if($article->showToc())