Skip to content

Commit 90b460b

Browse files
authored
Fix post preview (#81)
* ♿ Update Article detail view * ⏪ remove word
1 parent 79490ce commit 90b460b

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

app/Http/Controllers/ArticlesController.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@ public function show(Article $article)
2727

2828
views($article)->record();
2929

30+
/** @var Article $article */
3031
$article = Cache::remember('post-'.$article->id, now()->addHour(), fn () => $article);
3132

3233
abort_unless(
3334
$article->isPublished() || ($user && $article->isAuthoredBy($user)) || ($user && $user->hasAnyRole(['admin', 'moderator'])), // @phpstan-ignore-line
3435
404
3536
);
3637

38+
$image = $article->getFirstMediaUrl('media') ?? asset('images/socialcard.png');
3739
seo()
3840
->title($article->title)
3941
->description($article->excerpt(100))
40-
->image($article->getFirstMediaUrl('media'))
42+
->image($image)
4143
->twitterTitle($article->title)
4244
->twitterDescription($article->excerpt(100))
43-
->twitterImage($article->getFirstMediaUrl('media'))
45+
->twitterImage($image)
4446
->twitterSite('laravelcm')
4547
->withUrl();
4648

app/Http/Livewire/Articles/Edit.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Models\User;
88
use App\Traits\WithArticleAttributes;
99
use App\Traits\WithTagsAssociation;
10+
use Illuminate\Contracts\View\View;
1011
use Illuminate\Support\Facades\Auth;
1112
use Illuminate\Support\Facades\Cache;
1213
use Livewire\Component;
@@ -38,19 +39,19 @@ public function mount(Article $article)
3839
$this->associateTags = $this->tags_selected = old('tags', $article->tags()->pluck('id')->toArray());
3940
}
4041

41-
public function submit()
42+
public function submit(): void
4243
{
4344
$this->alreadySubmitted = $this->article->submitted_at !== null;
4445
$this->submitted_at = $this->article->submitted_at ?? now();
4546
$this->store();
4647
}
4748

48-
public function store()
49+
public function store(): void
4950
{
5051
$this->save();
5152
}
5253

53-
public function save()
54+
public function save(): void
5455
{
5556
$this->validate();
5657

@@ -80,7 +81,7 @@ public function save()
8081
$this->redirectRoute('articles.show', $this->article);
8182
}
8283

83-
public function render()
84+
public function render(): View
8485
{
8586
return view('livewire.articles.edit', [
8687
'tags' => Tag::whereJsonContains('concerns', ['post'])->get(),

app/Models/Article.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function isPublished(): bool
207207

208208
public function isNotPublished(): bool
209209
{
210-
return ($this->isNotSubmitted() || $this->isNotApproved()) && $this->published_at === null;
210+
return $this->isNotSubmitted() || $this->isNotApproved();
211211
}
212212

213213
public function isPinned(): bool

resources/views/articles/show.blade.php

+30-21
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<div class="hidden relative lg:block lg:col-span-2">
1515
<x-sticky-content class="divide-y divide-skin-base space-y-6">
1616
<div>
17-
<h4 class="text-xs text-skin-base font-medium leading-4 tracking-wide uppercase font-heading">A propos de l’auteur</h4>
17+
<h4 class="text-xs text-skin-base font-medium leading-4 tracking-wide uppercase font-heading">{{ __('A propos de l’auteur') }}</h4>
1818
<div class="mt-6 space-y-4">
1919
<a href="{{ route('profile', $author->username) }}" class="shrink-0 block">
2020
<div class="flex items-center">
@@ -107,12 +107,14 @@
107107
<div class="mt-2 flex space-x-1 text-sm text-skin-base sm:mt-0">
108108
<time class="capitalize" datetime="{{ $article->publishedAt()->format('Y-m-d') }}">{{ $article->publishedAt()->isoFormat('LL') }}</time>
109109
<span aria-hidden="true">&middot;</span>
110-
<span>{{ $article->readTime() }} min de lecture</span>
110+
<span>{{ __(':time min de lecture', ['time' => $article->readTime()]) }}</span>
111111
<span aria-hidden="true">&middot;</span>
112-
<span>{{ $article->views_count }} vues</span>
112+
<span>{{ __(':views vues', ['views' => $article->views_count]) }}</span>
113113
</div>
114114
</div>
115-
<h1 class="text-2xl font-extrabold text-skin-inverted tracking-tight font-heading sm:text-3xl sm:leading-10 md:text-4xl lg:text-5xl lg:leading-[3.5rem]">{{ $article->title }}</h1>
115+
<h1 class="text-2xl font-extrabold text-skin-inverted tracking-tight font-heading sm:text-3xl sm:leading-10 md:text-4xl lg:text-5xl lg:leading-[3.5rem]">
116+
{{ $article->title }}
117+
</h1>
116118
<a href="{{ route('profile', $article->author->username) }}" class="mt-3 shrink-0 group block lg:hidden">
117119
<div class="flex items-center">
118120
<div>
@@ -129,11 +131,17 @@
129131
</div>
130132
</a>
131133
</header>
132-
<div class="mt-6 aspect-w-4 aspect-h-2 sm:mt-8 mx-auto">
133-
<img class="object-cover shadow-lg rounded-lg group-hover:opacity-75" src="{{ $article->getFirstMediaUrl('media') }}" alt="{{ $article->title }}" />
134-
</div>
135134

136-
<x-markdown-content id="content" class="mt-8 prose prose-lg prose-green text-skin-base mx-auto overflow-x-hidden md:prose-xl lg:max-w-none" :content="$article->body" />
135+
@if($media = $article->getFirstMediaUrl('media'))
136+
<div class="mt-6 aspect-w-4 aspect-h-2 sm:mt-8 mx-auto">
137+
<img class="object-cover shadow-lg rounded-lg group-hover:opacity-75" src="{{ $media }}" alt="{{ $article->title }}" />
138+
</div>
139+
@endif
140+
141+
<x-markdown-content
142+
id="content"
143+
class="mt-8 prose prose-lg prose-green text-skin-base mx-auto overflow-x-hidden md:prose-xl lg:max-w-none"
144+
:content="$article->body" />
137145

138146
<div class="mt-6 pt-5 border-t border-skin-base sm:hidden">
139147
<div class="space-y-4">
@@ -183,7 +191,7 @@
183191
</div>
184192

185193
<div class="py-6">
186-
<p class="text-base text-skin-base font-normal">Vous aimez cet article ? Faite le savoir en partageant</p>
194+
<p class="text-base text-skin-base font-normal">{{ __('Vous aimez cet article ? Faite le savoir en partageant') }}</p>
187195
<div class="mt-4 space-y-4 sm:flex sm:items-center sm:space-y-0 sm:space-x-4">
188196
<a href="https://twitter.com/share?text={{ urlencode('"'.$article->title.'" par '. ($article->author->twitter() ? '@'.$article->author->twitter() : $article->author->name) . ' #caparledev - ') }}&url={{ urlencode(route('articles.show', $article)) }}"
189197
class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md shadow-sm bg-skin-button text-sm leading-5 font-normal text-skin-base hover:bg-skin-button-hover focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-body focus:ring-green-500">
@@ -211,18 +219,19 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha
211219
<div class="relative flex justify-center">
212220
<span class="relative z-0 inline-flex shadow-sm rounded-md -space-x-px">
213221
<a href="{{ route('articles.edit', $article) }}" class="relative inline-flex items-center px-4 py-2 rounded-l-md border border-skin-base bg-skin-card text-sm font-medium text-skin-inverted-muted hover:bg-skin-card-muted focus:z-10 focus:outline-none focus:ring-1 focus:ring-green-500 focus:border-green-500 focus:ring-offset-body">
214-
<span class="sr-only">Éditer</span>
222+
<span class="sr-only">{{ __('Éditer') }}</span>
215223
<x-heroicon-s-pencil class="h-5 w-5" />
216224
</a>
217225
@if($article->isNotApproved())
218226
@hasanyrole('admin|moderator')
219227
<button onclick="Livewire.emit('openModal', 'modals.approved-article', {{ json_encode([$article->id]) }})" type="button" class="-ml-px relative inline-flex items-center px-4 py-2 border border-skin-base bg-skin-card text-sm font-medium text-green-500 hover:bg-skin-card-muted focus:z-10 focus:outline-none focus:ring-1 focus:ring-green-500 focus:border-green-500 focus:border-green-500 focus:ring-offset-body">
228+
<span class="sr-only">{{ __('Approuver') }}</span>
220229
<x-heroicon-s-badge-check class="h-5 w-5" />
221230
</button>
222231
@endhasanyrole
223232
@endif
224233
<button onclick="Livewire.emit('openModal', 'modals.delete-article', {{ json_encode([$article->id]) }})" type="button" class="relative inline-flex items-center px-4 py-2 rounded-r-md border border-skin-base bg-skin-card text-sm font-medium text-skin-inverted-muted hover:bg-skin-card-muted focus:z-10 focus:outline-none focus:ring-1 focus:ring-green-500 focus:border-green-500 focus:ring-offset-body">
225-
<span class="sr-only">Supprimer</span>
234+
<span class="sr-only">{{ __('Supprimer') }}</span>
226235
<x-heroicon-s-trash class="h-5 w-5" />
227236
</button>
228237
</span>
@@ -235,25 +244,25 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha
235244
<div class="space-y-8 py-8 sm:flex sm:items-center sm:justify-between sm:space-y-0">
236245
@if($next)
237246
<div>
238-
<h2 class="text-xs leading-5 tracking-wide uppercase text-skin-base">Article suivant</h2>
247+
<h2 class="text-xs leading-5 tracking-wide uppercase text-skin-base">{{ __('Article suivant') }}</h2>
239248
<div class="mt-3 flex items-start space-x-2">
240-
<img class="h-10 w-10 object-cover shadow-lg rounded-md" src="{{ $next->getFirstMediaUrl('media') }}" alt="{{ $next->slug }}">
249+
<img class="h-10 w-10 object-cover shadow-lg rounded-md" src="{{ $next->getFirstMediaUrl('media') ?? asset('images/socialcard.png') }}" alt="{{ $next->slug }}">
241250
<div class="flex flex-col space-y-1">
242251
<a class="text-base font-medium leading-4 text-skin-inverted hover:text-skin-primary-hover line-clamp-2" href="{{ route('articles.show', $next) }}">{{ $next->title }}</a>
243-
<span class="text-sm text-skin-muted">{{ $next->readTime() }} min de lecture</span>
252+
<span class="text-sm text-skin-muted">{{ __(':time min de lecture', ['time' => $next->readTime()]) }}</span>
244253
</div>
245254
</div>
246255
</div>
247256
@endif
248257

249258
@if($previous)
250259
<div>
251-
<h2 class="text-xs leading-5 tracking-wide uppercase text-skin-base">Article précédent</h2>
260+
<h2 class="text-xs leading-5 tracking-wide uppercase text-skin-base">{{ __('Article précédent') }}</h2>
252261
<div class="mt-3 flex items-start space-x-2">
253-
<img class="h-10 w-10 object-cover shadow-lg rounded-md" src="{{ $previous->getFirstMediaUrl('media') }}" alt="{{ $previous->slug }}">
262+
<img class="h-10 w-10 object-cover shadow-lg rounded-md" src="{{ $previous->getFirstMediaUrl('media') ?? asset('images/socialcard.png') }}" alt="{{ $previous->slug }}">
254263
<div class="flex flex-col space-y-1">
255264
<a class="text-base font-medium leading-4 text-skin-inverted hover:text-skin-primary-hover line-clamp-2" href="{{ route('articles.show', $previous) }}">{{ $previous->title }}</a>
256-
<span class="text-sm text-skin-muted">{{ $previous->readTime() }} min de lecture</span>
265+
<span class="text-sm text-skin-muted">{{ __(':time min de lecture', ['time' => $previous->readTime()]) }}</span>
257266
</div>
258267
</div>
259268
</div>
@@ -268,7 +277,7 @@ class="inline-flex items-center py-2 px-4 border border-skin-base rounded-md sha
268277

269278
@if($article->showToc())
270279
<div class="bg-skin-card px-4 py-6 rounded-lg shadow-lg">
271-
<h4 class="text-sm text-skin-inverted font-semibold leading-tight tracking-widest uppercase">Table des matières</h4>
280+
<h4 class="text-sm text-skin-inverted font-semibold leading-tight tracking-widest uppercase">{{ __('Table des matières') }}</h4>
272281
<x-toc class="mt-4 toc" id="toc">{!! $article->body !!}</x-toc>
273282
</div>
274283
@endif
@@ -293,7 +302,7 @@ class="fixed z-30 right-0 top-40 flex items-center justify-center block px-1.5 p
293302
<path d="M9.143 4.571h12.571a2.286 2.286 0 000-4.571H9.143a2.286 2.286 0 000 4.571zM21.714 8H9.143a2.286 2.286 0 000 4.571h12.571a2.286 2.286 0 000-4.571zM21.714 16H9.143a2.286 2.286 0 000 4.571h12.571a2.286 2.286 0 100-4.571z" />
294303
</g>
295304
</svg>
296-
<span class="hidden ml-1 text-sm font-semibold uppercase md:block">Sommaire</span>
305+
<span class="hidden ml-1 text-sm font-semibold uppercase md:block">{{ __('Sommaire') }}</span>
297306
</button>
298307

299308
<div
@@ -319,10 +328,10 @@ class="w-screen max-w-xs"
319328
<div class="h-[450px] flex flex-col py-6 bg-skin-card shadow-xl rounded-l-lg overflow-y-scroll">
320329
<div class="px-4 sm:px-6">
321330
<div class="flex items-start justify-between">
322-
<h2 class="text-lg font-medium text-skin-inverted" id="slide-over-title">Table des Matières</h2>
331+
<h2 class="text-lg font-medium text-skin-inverted" id="slide-over-title">{{ __('Table des Matières') }}</h2>
323332
<div class="ml-3 h-7 flex items-center">
324333
<button type="button" class="bg-skin-card rounded-md text-skin-muted hover:text-skin-base focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500" @click="openTOC = false">
325-
<span class="sr-only">Fermer</span>
334+
<span class="sr-only">{{ __('Fermer') }}</span>
326335
<x-heroicon-o-x class="h-6 w-6" />
327336
</button>
328337
</div>

resources/views/livewire/user/activities.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="flow-root">
22
<h3 class="mt-4 text-lg leading-6 font-medium text-skin-inverted font-sans">
3-
{{ __('Dernières activités de4 :name', ['name' => $user->name]) }}
3+
{{ __('Dernières activités de :name', ['name' => $user->name]) }}
44
</h3>
55
<ul role="list" class="mt-6 -mb-8">
66
@forelse($activities as $activity)

0 commit comments

Comments
 (0)