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