Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
MarkdownPost | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
getLatestPosts | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
toArray | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Hyde\Pages; |
6 | |
7 | use Hyde\Foundation\Kernel\PageCollection; |
8 | use Hyde\Framework\Features\Blogging\Models\FeaturedImage; |
9 | use Hyde\Framework\Features\Blogging\Models\PostAuthor; |
10 | use Hyde\Markdown\Contracts\FrontMatter\BlogPostSchema; |
11 | use Hyde\Pages\Concerns\BaseMarkdownPage; |
12 | use Hyde\Support\Models\DateString; |
13 | |
14 | use function array_merge; |
15 | |
16 | /** |
17 | * Page class for Markdown posts. |
18 | * |
19 | * Markdown posts are stored in the _posts directory and using the .md extension. |
20 | * The Markdown will be compiled to HTML using the blog post layout to the _site/posts/ directory. |
21 | * |
22 | * @see https://hydephp.com/docs/1.x/blog-posts |
23 | */ |
24 | class MarkdownPost extends BaseMarkdownPage implements BlogPostSchema |
25 | { |
26 | public static string $sourceDirectory = '_posts'; |
27 | public static string $outputDirectory = 'posts'; |
28 | public static string $template = 'hyde::layouts/post'; |
29 | |
30 | public ?string $description; |
31 | public ?string $category; |
32 | public ?DateString $date; |
33 | public ?PostAuthor $author; |
34 | public ?FeaturedImage $image; |
35 | |
36 | /** @return \Hyde\Foundation\Kernel\PageCollection<\Hyde\Pages\MarkdownPost> */ |
37 | public static function getLatestPosts(): PageCollection |
38 | { |
39 | return static::all()->sortByDesc(function (self $post): int { |
40 | return $post->date?->dateTimeObject->getTimestamp() ?? 0; |
41 | }); |
42 | } |
43 | |
44 | public function toArray(): array |
45 | { |
46 | return array_merge(parent::toArray(), [ |
47 | 'description' => $this->description, |
48 | 'category' => $this->category, |
49 | 'date' => $this->date, |
50 | 'author' => $this->author, |
51 | 'image' => $this->image, |
52 | ]); |
53 | } |
54 | } |