-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMarkdownPostParser.php
42 lines (34 loc) · 1.01 KB
/
MarkdownPostParser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Hyde\Framework\Models\Parsers;
use Hyde\Framework\Contracts\AbstractPageParser;
use Hyde\Framework\Hyde;
use Hyde\Framework\Models\Pages\MarkdownPost;
use Hyde\Framework\Services\MarkdownFileService;
class MarkdownPostParser extends AbstractPageParser
{
protected string $pageModel = MarkdownPost::class;
protected string $slug;
/** @deprecated (handled in constructor) */
public string $title = '';
public string $body;
public array $matter;
public function execute(): void
{
$document = (new MarkdownFileService(
Hyde::getMarkdownPostPath("/$this->slug.md")
))->get();
$this->matter = array_merge($document->matter, [
'slug' => $this->slug,
]);
$this->body = $document->body;
}
public function get(): MarkdownPost
{
return new MarkdownPost(
matter: $this->matter,
body: $this->body,
title: $this->title,
slug: $this->slug
);
}
}