Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
MarkdownPost | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
getCurrentPagePath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getCanonicalLink | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPostDescription | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getLatestPosts | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Hyde\Framework\Models; |
4 | |
5 | use Hyde\Framework\Concerns\GeneratesPageMetadata; |
6 | use Hyde\Framework\Concerns\HasAuthor; |
7 | use Hyde\Framework\Concerns\HasDateString; |
8 | use Hyde\Framework\Concerns\HasFeaturedImage; |
9 | use Hyde\Framework\Hyde; |
10 | use Hyde\Framework\Models\Parsers\MarkdownPostParser; |
11 | use Illuminate\Support\Collection; |
12 | |
13 | class MarkdownPost extends MarkdownDocument |
14 | { |
15 | use HasAuthor; |
16 | use GeneratesPageMetadata; |
17 | use HasDateString; |
18 | use HasFeaturedImage; |
19 | |
20 | public ?string $category; |
21 | |
22 | public static string $sourceDirectory = '_posts'; |
23 | public static string $parserClass = MarkdownPostParser::class; |
24 | |
25 | /** |
26 | * @throws \Hyde\Framework\Exceptions\CouldNotParseDateStringException |
27 | */ |
28 | public function __construct(array $matter, string $body, string $title = '', string $slug = '') |
29 | { |
30 | parent::__construct($matter, $body, $title, $slug); |
31 | |
32 | $this->constructAuthor(); |
33 | $this->constructMetadata(); |
34 | $this->constructDateString(); |
35 | $this->constructFeaturedImage(); |
36 | |
37 | $this->category = $this->matter['category'] ?? null; |
38 | } |
39 | |
40 | public function getCurrentPagePath(): string |
41 | { |
42 | return 'posts/'.$this->slug; |
43 | } |
44 | |
45 | public function getCanonicalLink(): string |
46 | { |
47 | return Hyde::uriPath(Hyde::pageLink($this->getCurrentPagePath().'.html')); |
48 | } |
49 | |
50 | public function getPostDescription(): string |
51 | { |
52 | return $this->matter['description'] ?? substr($this->body, 0, 125).'...'; |
53 | } |
54 | |
55 | public static function getLatestPosts(): Collection |
56 | { |
57 | return static::all()->sortByDesc('matter.date'); |
58 | } |
59 | } |