Skip to content

Commit 282e1e7

Browse files
committed
WIP
- Enhance Article model and improve home page text rendering
1 parent 4fde239 commit 282e1e7

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

site/blueprints/site.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tabs:
1313
type: pages
1414
layout: cards
1515
status: published
16+
flip: true
1617
image:
1718
cover: true
1819
ratio: 16/9

site/models/article.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
use Kirby\Cms\Block;
4+
use Kirby\Cms\Page;
5+
use Kirby\Toolkit\Str;
6+
7+
class ArticlePage extends Page
8+
{
9+
public function abstract(): string
10+
{
11+
$abstract = $this->getAbstract();
12+
13+
return match(true) {
14+
!empty($abstract) => $abstract,
15+
$this->subtitle()->isNoEmpty() => $this->subtitle(),
16+
default => $this->title(),
17+
};
18+
}
19+
20+
protected function getAbstract(): null|string
21+
{
22+
if ($this->blocks()->isEmpty()) {
23+
return null;
24+
}
25+
26+
$text = $this
27+
->blocks()
28+
->toBlocks()
29+
->filter(fn($block) => $block->type() === 'text');
30+
31+
if($text->isEmpty()) {
32+
return null;
33+
}
34+
35+
return Str::excerpt($text);
36+
}
37+
}

site/templates/home.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{{ $article->title() }}
1313
</div>
1414
<div class="font-thin font-inter text-gray-600">
15-
{{ $article->subtitle() }}
15+
{{ $article->abstract() }}
1616
</div>
1717
</div>
1818
<img src="{{ $article->image()->url() }}" alt="{{ $article->title() }}" class="w-full sm:w-32 sm:h-28 object-cover shadow-md sm:ml-6 mt-3 sm:mt-0">

site/templates/search.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
</div>
2121
<div class="font-thin font-inter text-gray-600">
2222
{!! $highlightedSubtitle !!}
23+
{{ $article->greatings() }}
2324
</div>
2425
</div>
2526
@empty(!$article->image())

0 commit comments

Comments
 (0)