|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Concerns\FrontMatter\Schemas; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Actions\Constructors\ConfiguresFeaturedImageForPost; |
|
6
|
|
|
use Hyde\Framework\Actions\Constructors\FindsAuthorForPost; |
|
7
|
|
|
use Hyde\Framework\Models\Author; |
|
8
|
|
|
use Hyde\Framework\Models\DateString; |
|
9
|
|
|
use Hyde\Framework\Models\Image; |
|
10
|
|
|
|
|
11
|
|
|
trait BlogPostSchema |
|
12
|
|
|
{ |
|
13
|
|
|
/** @example "My New Post" */ |
|
14
|
|
|
public string $title; |
|
15
|
|
|
|
|
16
|
|
|
/** @example "A short description" */ |
|
17
|
|
|
public ?string $description = null; |
|
18
|
|
|
|
|
19
|
|
|
/** @example "general", "my favorite recipes" */ |
|
20
|
|
|
public ?string $category = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The date the post was published. |
|
24
|
|
|
* |
|
25
|
|
|
* @example 'YYYY-MM-DD [HH:MM]' (Must be parsable by `strtotime()`) |
|
26
|
|
|
* @yamlType string|optional |
|
27
|
|
|
*/ |
|
28
|
|
|
public ?DateString $date = null; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @example See author section |
|
32
|
|
|
* @yamlType string|array|optional |
|
33
|
|
|
*/ |
|
34
|
|
|
public ?Author $author = null; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @example See image section |
|
38
|
|
|
* @yamlType string|array|optional |
|
39
|
|
|
*/ |
|
40
|
|
|
public ?Image $image = null; |
|
41
|
|
|
|
|
42
|
|
|
protected function constructBlogPostSchema(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$this->category = $this->matter('category'); |
|
|
|
|
|
|
45
|
|
|
$this->description = $this->matter('description', substr($this->markdown, 0, 125).'...'); |
|
46
|
|
|
$this->date = $this->matter('date') !== null ? new DateString($this->matter('date')) : null; |
|
47
|
|
|
$this->author = FindsAuthorForPost::run($this); |
|
48
|
|
|
$this->image = ConfiguresFeaturedImageForPost::run($this); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|