|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Models\Parsers; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Contracts\AbstractPageParser; |
|
6
|
|
|
use Hyde\Framework\Hyde; |
|
7
|
|
|
use Hyde\Framework\Models\Pages\DocumentationPage; |
|
8
|
|
|
use Hyde\Framework\Services\MarkdownFileService; |
|
9
|
|
|
use Illuminate\Support\Str; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Parses a Markdown file in the configured docs directory into a DocumentationPage object. |
|
13
|
|
|
* |
|
14
|
|
|
* If the file is in a subdirectory relative to the base source directory (default _docs), |
|
15
|
|
|
* the subdirectory name will be used as the page's category. This only works for one level, |
|
16
|
|
|
* and the resulting file will still be put in the root of the docs output directory. |
|
17
|
|
|
*/ |
|
18
|
|
|
class DocumentationPageParser extends AbstractPageParser |
|
19
|
|
|
{ |
|
20
|
|
|
protected string $pageModel = DocumentationPage::class; |
|
21
|
|
|
protected string $slug; |
|
22
|
|
|
|
|
23
|
|
|
/** @deprecated v0.44.x (handled in constructor) */ |
|
24
|
|
|
public string $title = ''; |
|
25
|
|
|
public string $body; |
|
26
|
|
|
public array $matter; |
|
27
|
|
|
|
|
28
|
|
|
public function execute(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$document = (new MarkdownFileService( |
|
31
|
|
|
Hyde::getDocumentationPagePath("/$this->slug.md") |
|
32
|
|
|
))->get(); |
|
33
|
|
|
|
|
34
|
|
|
$this->body = $document->body; |
|
35
|
|
|
$this->matter = $document->matter; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function get(): DocumentationPage |
|
39
|
|
|
{ |
|
40
|
|
|
return new DocumentationPage( |
|
41
|
|
|
matter: $this->matter, |
|
42
|
|
|
body: $this->body, |
|
43
|
|
|
title: $this->title, |
|
|
|
|
|
|
44
|
|
|
slug: basename($this->slug), |
|
45
|
|
|
category: $this->getCategory(), |
|
46
|
|
|
localPath: $this->slug |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getCategory(): ?string |
|
51
|
|
|
{ |
|
52
|
|
|
if (str_contains($this->slug, '/')) { |
|
53
|
|
|
return Str::before($this->slug, '/'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this->matter['category'] ?? null; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.