Skip to content

Commit 78980fa

Browse files
committed
Module refactoring.
1 parent 56db959 commit 78980fa

File tree

7 files changed

+140
-109
lines changed

7 files changed

+140
-109
lines changed

stubs/modules/Blog/Database/Factories/BlogPostFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function definition(): array
1818
'title' => $title,
1919
'slug' => Str::slug($title),
2020
'content' => $this->faker->realText(),
21+
'summary' => $this->faker->realText(100),
2122
'image' => $this->faker->imageUrl(),
2223
'meta_tag_title' => Str::limit($title, 60, ''),
2324
'meta_tag_description' => Str::limit($title, 160, ''),

stubs/modules/Blog/Database/Migrations/2023_11_29_165237_create_blog_posts_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function up(): void
1717
$table->foreignId('blog_category_id')->nullable();
1818
$table->string('title');
1919
$table->string('slug')->unique();
20+
$table->text('summary')->nullable();
2021
$table->longText('content');
2122
$table->string('image')->nullable();
2223
$table->string('meta_tag_title', 60)->nullable();

stubs/modules/Blog/Http/Requests/PostValidate.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public function rules(): array
1313
'blog_category_id' => 'nullable|exists:blog_categories,id',
1414
'title' => 'required|string|max:255',
1515
'content' => 'required|string',
16+
'summary' => 'nullable|string|max:65535', //database text field size
1617
'image' => 'nullable|image|max:2048', //Max size 2MB
1718
'meta_tag_title' => 'nullable|string|max:60',
1819
'meta_tag_description' => 'nullable|string|max:160',

stubs/modules/Blog/Tests/PostTest.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
afterEach(function () {
2424
if ($this->post->image) {
25-
Storage::disk('public')->delete('blog/'.$this->post->image);
25+
Storage::disk('public')->delete('blog/' . $this->post->image);
2626
}
2727
});
2828

@@ -32,12 +32,12 @@
3232
$response->assertStatus(200);
3333

3434
$response->assertInertia(
35-
fn (Assert $page) => $page
35+
fn(Assert $page) => $page
3636
->component('BlogPost/PostIndex')
3737
->has(
3838
'posts.data',
3939
1,
40-
fn (Assert $page) => $page
40+
fn(Assert $page) => $page
4141
->where('id', $this->post->id)
4242
->where('image_url', $this->post->image_url)
4343
->where('title', $this->post->title)
@@ -52,7 +52,7 @@
5252
$response->assertStatus(200);
5353

5454
$response->assertInertia(
55-
fn (Assert $page) => $page
55+
fn(Assert $page) => $page
5656
->component('BlogPost/PostForm')
5757
);
5858
});
@@ -62,6 +62,7 @@
6262
'blog_author_id' => null,
6363
'blog_category_id' => null,
6464
'title' => 'Post Title',
65+
'summary' => 'Post Summary',
6566
'content' => 'Post Content',
6667
'image' => null,
6768
'meta_tag_title' => 'Post Title Tag',
@@ -77,21 +78,22 @@
7778
});
7879

7980
test('post edit page can be rendered', function () {
80-
$response = $this->loggedRequest->get('/admin/blog-post/'.$this->post->id.'/edit');
81+
$response = $this->loggedRequest->get('/admin/blog-post/' . $this->post->id . '/edit');
8182

8283
$response->assertStatus(200);
8384

8485
$response->assertInertia(
85-
fn (Assert $page) => $page
86+
fn(Assert $page) => $page
8687
->component('BlogPost/PostForm')
8788
->has(
8889
'post',
89-
fn (Assert $page) => $page
90+
fn(Assert $page) => $page
9091
->where('id', $this->post->id)
9192
->where('blog_author_id', $this->post->blog_author_id)
9293
->where('blog_category_id', $this->post->blog_category_id)
9394
->where('title', $this->post->title)
9495
->where('slug', $this->post->slug)
96+
->where('summary', $this->post->summary)
9597
->where('content', $this->post->content)
9698
->where('image', $this->post->image)
9799
->where('image_url', $this->post->image_url)
@@ -104,10 +106,11 @@
104106
});
105107

106108
test('post can be updated', function () {
107-
$response = $this->loggedRequest->put('/admin/blog-post/'.$this->post->id, [
109+
$response = $this->loggedRequest->put('/admin/blog-post/' . $this->post->id, [
108110
'blog_author_id' => null,
109111
'blog_category_id' => null,
110112
'title' => 'New Post Title',
113+
'summary' => 'Post Summary',
111114
'content' => 'Post Content',
112115
'meta_tag_title' => 'Post Title Tag',
113116
'meta_tag_description' => 'Post Description Tag',
@@ -118,12 +121,12 @@
118121

119122
$redirectResponse = $this->loggedRequest->get('/admin/blog-post');
120123
$redirectResponse->assertInertia(
121-
fn (Assert $page) => $page
124+
fn(Assert $page) => $page
122125
->component('BlogPost/PostIndex')
123126
->has(
124127
'posts.data',
125128
1,
126-
fn (Assert $page) => $page
129+
fn(Assert $page) => $page
127130
->where('id', $this->post->id)
128131
->where('title', 'New Post Title')
129132
->where('image_url', $this->post->image_url)
@@ -133,7 +136,7 @@
133136
});
134137

135138
test('post can be deleted', function () {
136-
$response = $this->loggedRequest->delete('/admin/blog-post/'.$this->user->id);
139+
$response = $this->loggedRequest->delete('/admin/blog-post/' . $this->user->id);
137140

138141
$response->assertRedirect('/admin/blog-post');
139142

stubs/modules/Blog/views/post-index.blade.php

Lines changed: 86 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,127 @@
11
@extends('site-layout')
22

3+
@section('meta-title')
4+
Blog
5+
@stop
6+
7+
@section('meta-description')
8+
Here you will find the latest news and updates about us.
9+
@stop
10+
311
@section('bodyEndScripts')
412
@vite('resources-site/js/blog-app.js')
513
@endsection
614

715
@section('content')
8-
<blog-toolbar :archive-options="{{ json_encode($archiveOptions) }}" :tags="{{ json_encode($tags) }}">
9-
</blog-toolbar>
16+
<blog-toolbar :archive-options="{{ json_encode($archiveOptions) }}" :tags="{{ json_encode($tags) }}"></blog-toolbar>
1017

11-
<div class="bg-white py-24 sm:py-32">
18+
<div class="bg-skin-neutral-2 py-24 sm:py-32">
1219
<div class="mx-auto max-w-7xl px-6 lg:px-8">
1320
<!-- Section Title -->
1421
<div class="mx-auto max-w-2xl text-center">
15-
<h2 class="text-3xl font-bold tracking-tight text-gray-900 sm:text-4xl">Blog</h2>
22+
<h2 class="text-3xl font-bold tracking-tight text-skin-neutral-11 sm:text-4xl">
23+
Blog
24+
</h2>
1625

17-
<p class="mt-2 text-lg leading-8 text-gray-600">
26+
<p class="mt-2 text-lg leading-8 text-skin-neutral-12">
1827
@if (isset($fromArchive))
19-
Posts from archive: <span class="font-semibold">{{ $fromArchive }}</span>
28+
Posts from archive:
29+
<span class="font-semibold">{{ $fromArchive }}</span>
2030
@elseif (isset($fromTag))
21-
Posts tagged with: <span class="font-semibold">{{ $fromTag }}</span>
31+
Posts tagged with:
32+
<span class="font-semibold">{{ $fromTag }}</span>
2233
@elseif (isset($fromSearch))
23-
Posts matching: <span class="font-semibold">{{ $fromSearch }}</span>
34+
Posts matching:
35+
<span class="font-semibold">{{ $fromSearch }}</span>
2436
@else
25-
Learn how to grow your business with our expert advice.
37+
<span>
38+
Here you will find the latest news and updates about
39+
us.
40+
</span>
2641
@endif
2742
</p>
2843
</div>
2944

3045
@if ($posts->count())
3146
<!-- Posts -->
32-
<div class="mx-auto mt-16 grid max-w-2xl grid-cols-1 gap-x-8 gap-y-20 lg:mx-0 lg:max-w-none lg:grid-cols-3">
33-
34-
47+
<div
48+
class="mx-auto mt-16 grid max-w-sm grid-cols-1 gap-x-8 gap-y-16 md:max-w-2xl md:grid-cols-2 lg:mx-0 lg:max-w-none lg:grid-cols-3">
3549
@foreach ($posts as $post)
36-
<article class="flex flex-col items-start justify-between">
37-
<div class="relative w-full">
38-
<a href="/blog/{{ $post->slug }}" class="block">
50+
<article class="rounded bg-skin-neutral-11">
51+
<a href="/blog/{{ $post->slug }}"
52+
class="flex flex-col items-start justify-between px-6 py-6 text-skin-neutral-2 transition-all duration-300 ease-out hover:bg-skin-neutral-12 hover:text-skin-neutral-1">
53+
<header class="relative w-full">
3954
@if ($post->image_url)
4055
<img src="{{ $post->image_url }}" alt="{{ $post->title }}"
41-
class="aspect-[16/9] w-full rounded-2xl bg-gray-100 object-cover sm:aspect-[2/1] lg:aspect-[3/2]">
56+
class="aspect-[16/9] w-full object-cover sm:aspect-[2/1] lg:aspect-[3/2]" />
4257
@else
4358
<div
44-
class="aspect-[16/9] w-full rounded-2xl sm:aspect-[2/1] lg:aspect-[3/2] flex items-center justify-center bg-gradient-to-bl from-skin-neutral-1 to-skin-neutral-6">
45-
<span class="text-lg text-skin-neutral-9">N/A</span>
59+
class="flex aspect-[16/9] w-full items-center justify-center rounded-2xl bg-gradient-to-bl from-skin-neutral-1 to-skin-neutral-6 sm:aspect-[2/1] lg:aspect-[3/2]">
60+
<span class="text-lg text-skin-neutral-9">
61+
N/A
62+
</span>
4663
</div>
4764
@endif
48-
<div class="absolute inset-0 rounded-2xl ring-1 ring-inset ring-gray-900/10"></div>
49-
</a>
50-
</div>
51-
<div class="max-w-xl">
52-
<div class="mt-8 flex items-center gap-2 text-xs">
53-
<div class="text-gray-600 italic flex items-center gap-1">
54-
55-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"
56-
class="h-3 w-3">
57-
<path
58-
d="M17 3H21C21.5523 3 22 3.44772 22 4V20C22 20.5523 21.5523 21 21 21H3C2.44772 21 2 20.5523 2 20V4C2 3.44772 2.44772 3 3 3H7V1H9V3H15V1H17V3ZM4 9V19H20V9H4ZM6 11H8V13H6V11ZM11 11H13V13H11V11ZM16 11H18V13H16V11Z">
59-
</path>
60-
</svg>
61-
{{ $post->published_at->format('F d, Y') }}
65+
<div class="absolute inset-0 rounded-2xl ring-1 ring-inset ring-skin-neutral-10/10">
6266
</div>
63-
64-
<div class="text-gray-600 italic flex items-center gap-1">
65-
@if ($post->author)
66-
@if ($post->author->image_url)
67-
<img src="{{ $post->author->image_url }}" alt="{{ $post->author->name }}"
68-
class="h-4 w-4 rounded-md bg-gray-100 object-cover">
69-
@else
70-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
71-
fill="currentColor" class="h-4 w-4">
72-
<path
73-
d="M4 22C4 17.5817 7.58172 14 12 14C16.4183 14 20 17.5817 20 22H4ZM12 13C8.685 13 6 10.315 6 7C6 3.685 8.685 1 12 1C15.315 1 18 3.685 18 7C18 10.315 15.315 13 12 13Z">
74-
</path>
75-
</svg>
67+
</header>
68+
<div class="max-w-xl">
69+
<div class="mt-8 flex items-center gap-2 text-xs">
70+
<div class="flex items-center gap-1 italic">
71+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"
72+
class="h-3 w-3">
73+
<path
74+
d="M17 3H21C21.5523 3 22 3.44772 22 4V20C22 20.5523 21.5523 21 21 21H3C2.44772 21 2 20.5523 2 20V4C2 3.44772 2 3 3 3H7V1H9V3H15V1H17V3ZM4 9V19H20V9H4ZM6 11H8V13H6V11ZM11 11H13V13H11V11ZM16 11H18V13H16V11Z">
75+
</path>
76+
</svg>
77+
{{ $post->published_at->format('F d, Y') }}
78+
</div>
79+
<div class="flex items-center gap-1 italic">
80+
@if ($post->author)
81+
@if ($post->author->image_url)
82+
<img src="{{ $post->author->image_url }}"
83+
alt="{{ $post->author->name }}"
84+
class="h-4 w-4 rounded-md bg-skin-neutral-2 object-cover" />
85+
@else
86+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"
87+
fill="currentColor" class="h-4 w-4">
88+
<path
89+
d="M4 22C4 17.5817 7.58172 14 12 14C16.4183 14 20 17.5817 20 22H4ZM12 13C8.685 13 6 10.315 6 7C6 3.685 8.685 1 12 1C15.315 1 18 3.685 18 7C18 10.315 15.315 13 12 13Z">
90+
</path>
91+
</svg>
92+
@endif
93+
{{ $post->author->name }}
7694
@endif
77-
{{ $post->author->name }}
78-
@endif
95+
</div>
7996
</div>
80-
</div>
81-
82-
<div class="group relative mb-2">
83-
<h3
84-
class="mt-3 text-lg font-semibold leading-6 text-gray-900 group-hover:text-gray-600 min-h-12 ">
85-
<a href="/blog/{{ $post->slug }}">
86-
<span class="absolute
87-
inset-0"></span>
97+
<div class="group relative mb-2">
98+
<h3 class="mb-2 mt-3 min-h-12 text-lg font-semibold leading-6">
99+
<span class="absolute inset-0"></span>
88100
{{ $post->title }}
89-
</a>
90-
</h3>
91-
<p class="mt-5 line-clamp-3 text-sm leading-6 text-gray-600">
92-
{{ Str::limit($post->content, 160) }}
93-
</p>
94-
</div>
95-
96-
<div class="mt-4 min-h-[44px]"> <!-- Reserve space for tags -->
97-
@foreach ($post->tags as $tag)
98-
<a href="/blog/tag/{{ $tag->slug }}"
99-
class="inline-block rounded px-3 py-1.5 text-sm bg-gray-200 mr-2 hover:bg-gray-100">
100-
{{ $tag->name }}
101-
</a>
102-
@endforeach
101+
</h3>
102+
<div class="line-clamp-3 text-sm leading-6">
103+
{!! $post->summary !!}
104+
</div>
105+
</div>
106+
@if ($post->tags->count())
107+
<footer class="mt-4 min-h-[44px]">
108+
@foreach ($post->tags as $tag)
109+
<a href="/blog/tag/{{ $tag->slug }}"
110+
class="mr-2 inline-block rounded bg-skin-neutral-1 px-3 py-1.5 text-sm">
111+
{{ $tag->name }}
112+
</a>
113+
@endforeach
114+
</footer>
115+
@endif
103116
</div>
104-
105-
</div>
117+
</a>
106118
</article>
107119
@endforeach
108-
109-
110120
</div>
111121
@else
112-
<p class="text-gray-600 bg-skin-neutral-3 px-4 py-2 rounded mt-2">No posts found.</p>
122+
<p class="mt-2 rounded bg-skin-neutral-3 px-4 py-2 text-skin-neutral-9">
123+
No posts found.
124+
</p>
113125
@endif
114126

115127
<div class="mt-12">

0 commit comments

Comments
 (0)