Skip to content

Commit

Permalink
Update PostResource and BlogSection for dynamic excerpt length and im…
Browse files Browse the repository at this point in the history
…proved translation keys
  • Loading branch information
abdessamadbettal committed Dec 13, 2024
1 parent 01e2236 commit b6d23a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/Http/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PostResource extends JsonResource
*/
public function toArray(Request $request): array
{
$excerptLength = Str::length($this->name) < 40 ? 110 : 70;
return [
'id' => $this->id,
'name' => Str::limit($this->name, 60, '...'),
Expand All @@ -24,7 +25,7 @@ public function toArray(Request $request): array
'thumbnail' => $this->getFirstMediaUrl('thumbnail') ?? null,
'image' => $this->getFirstMediaUrl('thumbnail') ?? null,
'content' => MarkdownHelper::convertToHtml($this->content),
'excerpt' => Str::limit($this->content, 60, '...'),
'excerpt' => Str::limit($this->content, $excerptLength, '...'),
'author' => new UserResource($this->author),
'category' => new CategoryResource($this->category),
'is_published' => $this->is_published,
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Components/Blog/BlogSection.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<template>
<div class="container relative md:mt-24 mt-16">
<div class="grid grid-cols-1 pb-6 text-center">
<h3 class="mb-6 md:text-3xl text-2xl md:leading-normal leading-normal font-semibold">{{ $t('latest_blogs')
<h3 class="mb-6 md:text-3xl text-2xl md:leading-normal leading-normal font-semibold">{{ $t('home.latest_blogs')
}}</h3>

<p class="text-slate-400 max-w-xl mx-auto">{{ $t('latest_blogs_text') }}</p>
<p class="text-slate-400 max-w-xl mx-auto">{{ $t('home.latest_blogs_text') }}</p>
</div>

<div class="grid lg:grid-cols-3 md:grid-cols-2 grid-cols-1 mt-6 gap-6">
Expand All @@ -21,7 +21,7 @@
<BlogCard v-else v-for="item in posts" :key="item.id" :item="item" />
</div>
<div class="mt-6 text-center">
<Link :href="route('posts.index')" class="text-slate-400 hover:text-primary-500 inline-block cursor-pointer">{{ $t('see_more_posts') }}
<Link :href="route('posts.index')" class="text-slate-400 hover:text-primary-500 inline-block cursor-pointer">{{ $t('home.see_more_posts') }}
<i class="mdi mdi-arrow-right align-middle"></i></Link>
</div>
</div>
Expand Down

0 comments on commit b6d23a1

Please sign in to comment.