|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Models\Pages; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Actions\GeneratesSidebarTableOfContents; |
|
6
|
|
|
use Hyde\Framework\Concerns\BaseMarkdownPage; |
|
7
|
|
|
use Hyde\Framework\Contracts\FrontMatter\DocumentationPageSchema; |
|
8
|
|
|
use Hyde\Framework\Models\Markdown\Markdown; |
|
9
|
|
|
use Hyde\Framework\Models\Support\Route; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Page class for documentation pages. |
|
13
|
|
|
* |
|
14
|
|
|
* Documentation pages are stored in the _docs directory and using the .md extension. |
|
15
|
|
|
* The Markdown will be compiled to HTML using the documentation page layout to the _site/docs/ directory. |
|
16
|
|
|
* |
|
17
|
|
|
* @see https://hydephp.com/docs/master/documentation-pages |
|
18
|
|
|
*/ |
|
19
|
|
|
class DocumentationPage extends BaseMarkdownPage implements DocumentationPageSchema |
|
20
|
|
|
{ |
|
21
|
|
|
public static string $sourceDirectory = '_docs'; |
|
22
|
|
|
public static string $outputDirectory = 'docs'; |
|
23
|
|
|
public static string $template = 'hyde::layouts/docs'; |
|
24
|
|
|
|
|
25
|
|
|
/** @inheritDoc */ |
|
26
|
|
|
public function getRouteKey(): string |
|
27
|
|
|
{ |
|
28
|
|
|
return trim(static::outputDirectory().'/'.basename($this->identifier), '/'); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** @internal */ |
|
32
|
|
|
public function getOnlineSourcePath(): string|false |
|
33
|
|
|
{ |
|
34
|
|
|
if (config('docs.source_file_location_base') === null) { |
|
35
|
|
|
return false; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return trim(config('docs.source_file_location_base'), '/').'/'.$this->identifier.'.md'; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public static function home(): ?Route |
|
42
|
|
|
{ |
|
43
|
|
|
return Route::exists(static::$outputDirectory.'/index') ? Route::get(static::$outputDirectory.'/index') : null; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function hasTableOfContents(): bool |
|
47
|
|
|
{ |
|
48
|
|
|
return config('docs.table_of_contents.enabled', true); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Generate Table of Contents as HTML from a Markdown document body. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function getTableOfContents(): string |
|
55
|
|
|
{ |
|
56
|
|
|
return (new GeneratesSidebarTableOfContents($this->markdown))->execute(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Return the output path for the identifier basename so nested pages are flattened. |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getOutputPath(): string |
|
63
|
|
|
{ |
|
64
|
|
|
return static::outputPath(basename($this->identifier)); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|