1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Models\Pages; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Concerns\HasTableOfContents; |
6
|
|
|
use Hyde\Framework\Contracts\AbstractMarkdownPage; |
7
|
|
|
use Hyde\Framework\Contracts\RouteContract; |
8
|
|
|
use Hyde\Framework\Models\Parsers\DocumentationPageParser; |
9
|
|
|
use Hyde\Framework\Models\Route; |
10
|
|
|
|
11
|
|
|
class DocumentationPage extends AbstractMarkdownPage |
12
|
|
|
{ |
13
|
|
|
use HasTableOfContents; |
14
|
|
|
|
15
|
|
|
public static string $sourceDirectory = '_docs'; |
16
|
|
|
public static string $outputDirectory = 'docs'; |
17
|
|
|
public static string $parserClass = DocumentationPageParser::class; |
18
|
|
|
public static string $template = 'hyde::layouts/docs'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The sidebar category group, if any. |
22
|
|
|
*/ |
23
|
|
|
public ?string $category; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The path to the page relative to the configured `_docs` directory. |
27
|
|
|
* Generally only needed if the page is in a subdirectory. |
28
|
|
|
*/ |
29
|
|
|
public ?string $localPath; |
30
|
|
|
|
31
|
|
|
public function __construct(array $matter = [], string $body = '', string $title = '', string $slug = '', ?string $category = null, ?string $localPath = null) |
32
|
|
|
{ |
33
|
|
|
parent::__construct($matter, $body, $title, $slug); |
34
|
|
|
$this->category = $category; |
35
|
|
|
$this->localPath = $localPath; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** @inheritDoc */ |
39
|
|
|
public function getSourcePath(): string |
40
|
|
|
{ |
41
|
|
|
return is_null($this->localPath) ? parent::getSourcePath() : static::qualifyBasename($this->localPath); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** @internal */ |
45
|
|
|
public function getOnlineSourcePath(): string|false |
46
|
|
|
{ |
47
|
|
|
if (config('docs.source_file_location_base') === null) { |
48
|
|
|
return false; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return trim(config('docs.source_file_location_base'), '/').'/'.$this->slug.'.md'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function home(): ?RouteContract |
55
|
|
|
{ |
56
|
|
|
return Route::exists('docs/index') ? Route::get('docs/index') : null; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public static function hasTableOfContents(): bool |
60
|
|
|
{ |
61
|
|
|
return config('docs.table_of_contents.enabled', true); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|