|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Contracts; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Actions\MarkdownConverter; |
|
6
|
|
|
use Hyde\Framework\Concerns\HasDynamicTitle; |
|
7
|
|
|
use Hyde\Framework\Models\MarkdownDocument; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The base class for all Markdown-based Page Models. |
|
11
|
|
|
* |
|
12
|
|
|
* @since 0.44.x replaces MarkdownDocument |
|
13
|
|
|
* |
|
14
|
|
|
* Extends the AbstractPage class to provide relevant |
|
15
|
|
|
* helpers for Markdown-based page model classes. |
|
16
|
|
|
* @see \Hyde\Framework\Models\Pages\MarkdownPage |
|
17
|
|
|
* @see \Hyde\Framework\Models\Pages\MarkdownPost |
|
18
|
|
|
* @see \Hyde\Framework\Models\Pages\DocumentationPage |
|
19
|
|
|
* @see \Hyde\Framework\Contracts\AbstractPage |
|
20
|
|
|
* |
|
21
|
|
|
* @test \Hyde\Framework\Testing\Feature\AbstractPageTest |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractMarkdownPage extends AbstractPage implements MarkdownPageContract |
|
24
|
|
|
{ |
|
25
|
|
|
use HasDynamicTitle; |
|
26
|
|
|
|
|
27
|
|
|
public MarkdownDocument $markdown; |
|
28
|
|
|
|
|
29
|
|
|
public array $matter; |
|
30
|
|
|
public string $body; |
|
31
|
|
|
public string $title; |
|
32
|
|
|
public string $slug; |
|
33
|
|
|
|
|
34
|
|
|
public static string $fileExtension = '.md'; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct(array $matter = [], string $body = '', string $title = '', string $slug = '', ?MarkdownDocument $markdownDocument = null) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->matter = $matter; |
|
39
|
|
|
$this->body = $body; |
|
40
|
|
|
$this->title = $title; |
|
41
|
|
|
$this->slug = $slug; |
|
42
|
|
|
|
|
43
|
|
|
$this->markdown = $markdownDocument ?? new MarkdownDocument($matter, $body); |
|
44
|
|
|
|
|
45
|
|
|
$this->constructDynamicTitle(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function markdown(): MarkdownDocument |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->markdown; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function matter(string $key = null, mixed $default = null): mixed |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->markdown->matter($key, $default); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** @inheritDoc */ |
|
59
|
|
|
public function compile(): string |
|
60
|
|
|
{ |
|
61
|
|
|
return view($this->getBladeView())->with([ |
|
62
|
|
|
'title' => $this->title, |
|
63
|
|
|
'markdown' => MarkdownConverter::parse($this->body, static::class), |
|
64
|
|
|
])->render(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|