1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Models\Pages; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Actions\GeneratesSidebarTableOfContents; |
6
|
|
|
use Hyde\Framework\Concerns\AbstractMarkdownPage; |
7
|
|
|
use Hyde\Framework\Contracts\FrontMatter\DocumentationPageSchema; |
8
|
|
|
use Hyde\Framework\Contracts\RouteContract; |
9
|
|
|
use Hyde\Framework\Models\FrontMatter; |
10
|
|
|
use Hyde\Framework\Models\Markdown; |
11
|
|
|
use Hyde\Framework\Models\Route; |
12
|
|
|
|
13
|
|
|
class DocumentationPage extends AbstractMarkdownPage implements DocumentationPageSchema |
14
|
|
|
{ |
15
|
|
|
public static string $sourceDirectory = '_docs'; |
16
|
|
|
public static string $outputDirectory = 'docs'; |
17
|
|
|
public static string $template = 'hyde::layouts/docs'; |
18
|
|
|
|
19
|
|
|
/** The sidebar category group, if any. Can be overridden in front matter, or by putting the source file in a subdirectory of the same category name. */ |
20
|
|
|
public ?string $category = null; |
21
|
|
|
|
22
|
|
|
/** The label for the page shown in the sidebar. */ |
23
|
|
|
public ?string $label = null; |
24
|
|
|
|
25
|
|
|
/** Hides the page from the sidebar. */ |
26
|
|
|
public ?bool $hidden = null; |
27
|
|
|
|
28
|
|
|
/** The priority of the page used for ordering the sidebar. */ |
29
|
|
|
public ?int $priority = null; |
30
|
|
|
|
31
|
|
|
/** @inheritDoc */ |
32
|
|
|
public function __construct(string $identifier = '', ?FrontMatter $matter = null, ?Markdown $markdown = null) |
33
|
|
|
{ |
34
|
|
|
parent::__construct($identifier, $matter, $markdown); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** @inheritDoc */ |
38
|
|
|
public function getRouteKey(): string |
39
|
|
|
{ |
40
|
|
|
return trim(static::outputDirectory().'/'.basename($this->identifier), '/'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** @internal */ |
44
|
|
|
public function getOnlineSourcePath(): string|false |
45
|
|
|
{ |
46
|
|
|
if (config('docs.source_file_location_base') === null) { |
47
|
|
|
return false; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
return trim(config('docs.source_file_location_base'), '/').'/'.$this->identifier.'.md'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public static function home(): ?RouteContract |
54
|
|
|
{ |
55
|
|
|
return Route::exists(static::$outputDirectory.'/index') ? Route::get(static::$outputDirectory.'/index') : null; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public static function hasTableOfContents(): bool |
59
|
|
|
{ |
60
|
|
|
return config('docs.table_of_contents.enabled', true); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Generate Table of Contents as HTML from a Markdown document body. |
65
|
|
|
*/ |
66
|
|
|
public function getTableOfContents(): string |
67
|
|
|
{ |
68
|
|
|
return (new GeneratesSidebarTableOfContents($this->markdown))->execute(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Return the output path for the identifier basename so nested pages are flattened. |
73
|
|
|
*/ |
74
|
|
|
public function getOutputPath(): string |
75
|
|
|
{ |
76
|
|
|
return static::outputPath(basename($this->identifier)); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|