Skip to content

Commit 8e7ceae

Browse files
authored
blog cleanup (#181)
Co-authored-by: ahinkle <17038330+ahinkle@users.noreply.github.com>
1 parent 79add49 commit 8e7ceae

38 files changed

Lines changed: 1064 additions & 1858 deletions

.github/workflows/fetch_podcasts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Setup PHP
1818
uses: shivammathur/setup-php@v2
1919
with:
20-
php-version: 8.3
20+
php-version: 8.4
2121
tools: composer:v2
2222
coverage: xdebug
2323

.github/workflows/quality_phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
21-
php-version: 8.3
21+
php-version: 8.4
2222
tools: composer:v2
2323
coverage: xdebug
2424

.github/workflows/quality_pint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
21-
php-version: 8.3
21+
php-version: 8.4
2222
tools: composer:v2
2323
coverage: xdebug
2424

.github/workflows/quality_rector.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
21-
php-version: 8.3
21+
php-version: 8.4
2222
tools: composer:v2
2323
coverage: xdebug
2424

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup PHP
1616
uses: shivammathur/setup-php@v2
1717
with:
18-
php-version: 8.3
18+
php-version: 8.4
1919
tools: composer:v2
2020
coverage: xdebug
2121

app/Models/Post.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\Models\Scopes\LatestPublishedOrderScope;
6+
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
7+
use Illuminate\Database\Eloquent\Casts\Attribute;
8+
use Illuminate\Database\Eloquent\Model;
9+
use Spatie\YamlFrontMatter\YamlFrontMatter;
10+
use Sushi\Sushi;
11+
use Symfony\Component\Finder\Finder;
12+
13+
#[ScopedBy(LatestPublishedOrderScope::class)]
14+
class Post extends Model
15+
{
16+
use Sushi;
17+
18+
protected function casts(): array
19+
{
20+
return [
21+
'published_at' => 'datetime',
22+
];
23+
}
24+
25+
/** @return array<int, array<string, mixed>> */
26+
public function getRows(): array
27+
{
28+
return collect($this->files())
29+
->map(fn (string $file): array => $this->parseFile($file))
30+
->sortByDesc('published_at')
31+
->values()
32+
->toArray();
33+
}
34+
35+
protected function files(): Finder
36+
{
37+
return Finder::create()
38+
->files()
39+
->in(resource_path('content/blog'))
40+
->name('*.md');
41+
}
42+
43+
/** @return array<string, mixed> */
44+
protected function parseFile(string $file): array
45+
{
46+
$document = YamlFrontMatter::parseFile($file);
47+
48+
// Default values for all possible fields
49+
$defaults = [
50+
'title' => '',
51+
'description' => '',
52+
'published_at' => null,
53+
'slug' => basename($file, '.md'),
54+
'content' => '',
55+
];
56+
57+
return array_merge(
58+
$defaults,
59+
$document->matter(),
60+
[
61+
'slug' => basename($file, '.md'), // Always override slug
62+
'content' => $document->body(), // Store markdown content
63+
],
64+
);
65+
}
66+
67+
/** @return Attribute<string, never> */
68+
protected function formattedDate(): Attribute
69+
{
70+
return Attribute::make(
71+
get: fn (): string => $this->getAttribute('published_at')?->format('F j, Y') ?? '',
72+
);
73+
}
74+
}

app/Providers/AppServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use Override;
56
use Illuminate\Foundation\Http\Events\RequestHandled;
67
use Illuminate\Support\Facades\Event;
78
use Illuminate\Support\Facades\Log;
@@ -12,6 +13,7 @@ class AppServiceProvider extends ServiceProvider
1213
/**
1314
* Register any application services.
1415
*/
16+
#[Override]
1517
public function register(): void
1618
{
1719
//

app/Providers/FolioServiceProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use Override;
56
use Illuminate\Support\ServiceProvider;
67
use Laravel\Folio\Folio;
78

@@ -10,6 +11,7 @@ class FolioServiceProvider extends ServiceProvider
1011
/**
1112
* Register services.
1213
*/
14+
#[Override]
1315
public function register(): void
1416
{
1517
//

app/View/Components/BlogListing.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@
22

33
namespace App\View\Components;
44

5-
use App\View\Components\Concerns\InteractsWithBlogPosts;
5+
use App\Models\Post;
66
use Closure;
77
use Illuminate\Contracts\View\View;
88
use Illuminate\View\Component;
99

1010
class BlogListing extends Component
1111
{
12-
use InteractsWithBlogPosts;
13-
1412
public function render(): View|Closure|string
1513
{
1614
return view('components.blog-listing', [
17-
'posts' => $this->resolvePosts(),
15+
'posts' => Post::all(),
1816
]);
1917
}
2018
}

app/View/Components/Concerns/InteractsWithBlogPosts.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)