Passed
Push — master ( 25efb9...c70e91 )
by Caen
04:09 queued 12s
created

MarkdownPost   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLatestPosts() 0 3 1
A toArray() 0 8 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
use function array_merge;
14
15
/**
16
 * Page class for Markdown posts.
17
 *
18
 * Markdown posts are stored in the _posts directory and using the .md extension.
19
 * The Markdown will be compiled to HTML using the blog post layout to the _site/posts/ directory.
20
 *
21
 * @see https://hydephp.com/docs/master/blog-posts
22
 */
23
class MarkdownPost extends BaseMarkdownPage implements BlogPostSchema
24
{
25
    public static string $sourceDirectory = '_posts';
26
    public static string $outputDirectory = 'posts';
27
    public static string $template = 'hyde::layouts/post';
28
29
    public ?string $description;
30
    public ?string $category;
31
    public ?DateString $date;
32
    public ?PostAuthor $author;
33
    public ?FeaturedImage $image;
34
35
    /** @return \Hyde\Foundation\Kernel\PageCollection<\Hyde\Pages\MarkdownPost> */
36
    public static function getLatestPosts(): PageCollection
37
    {
38
        return static::all()->sortByDesc('matter.date');
39
    }
40
41
    public function toArray(): array
42
    {
43
        return array_merge(parent::toArray(), [
44
            'description' => $this->description,
45
            'category' => $this->category,
46
            'date' => $this->date,
47
            'author' => $this->author,
48
            'image' => $this->image,
49
        ]);
50
    }
51
}
52