|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Concerns\Internal; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Actions\Constructors\FindsTitleForPage; |
|
6
|
|
|
use Hyde\Framework\Contracts\FrontMatter\BlogPostSchema; |
|
7
|
|
|
use Hyde\Framework\Contracts\FrontMatter\DocumentationPageSchema; |
|
8
|
|
|
use Hyde\Framework\Hyde; |
|
9
|
|
|
use Hyde\Framework\Models\Author; |
|
10
|
|
|
use Hyde\Framework\Models\DateString; |
|
11
|
|
|
use Hyde\Framework\Models\Image; |
|
12
|
|
|
|
|
13
|
|
|
trait ConstructsPageSchemas |
|
14
|
|
|
{ |
|
15
|
|
|
protected function constructPageSchemas(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$this->constructPageSchema(); |
|
18
|
|
|
|
|
19
|
|
|
if ($this instanceof BlogPostSchema) { |
|
20
|
|
|
$this->constructBlogPostSchema(); |
|
21
|
|
|
} |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
protected function constructPageSchema(): void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->title = FindsTitleForPage::run($this); |
|
|
|
|
|
|
27
|
|
|
$this->canonicalUrl = $this->makeCanonicalUrl(); |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
if ($this instanceof DocumentationPageSchema) { |
|
30
|
|
|
$this->constructSidebarNavigationData(); |
|
|
|
|
|
|
31
|
|
|
} else { |
|
32
|
|
|
$this->constructNavigationData(); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
protected function makeCanonicalUrl(): ?string |
|
37
|
|
|
{ |
|
38
|
|
|
if (! empty($this->matter('canonicalUrl'))) { |
|
|
|
|
|
|
39
|
|
|
return $this->matter('canonicalUrl'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if (Hyde::hasSiteUrl() && ! empty($this->identifier)) { |
|
43
|
|
|
return $this->getRoute()->getQualifiedUrl(); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return null; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected function constructBlogPostSchema(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->category = $this->matter('category'); |
|
|
|
|
|
|
52
|
|
|
$this->description = $this->matter('description', $this->makeDescription()); |
|
|
|
|
|
|
53
|
|
|
$this->date = $this->matter('date') !== null ? new DateString($this->matter('date')) : null; |
|
|
|
|
|
|
54
|
|
|
$this->author = $this->getAuthor(); |
|
|
|
|
|
|
55
|
|
|
$this->image = $this->getImage(); |
|
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function makeDescription(): string |
|
59
|
|
|
{ |
|
60
|
|
|
if (strlen($this->markdown) >= 128) { |
|
61
|
|
|
return substr($this->markdown, 0, 125).'...'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return (string) $this->markdown; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
protected function getAuthor(): ?Author |
|
68
|
|
|
{ |
|
69
|
|
|
if ($this->matter('author')) { |
|
70
|
|
|
return Author::make($this->matter('author')); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return null; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
protected function getImage(): ?Image |
|
77
|
|
|
{ |
|
78
|
|
|
if ($this->matter('image')) { |
|
79
|
|
|
return Image::make($this->matter('image')); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return null; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|