|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Hyde\Pages; |
|
6
|
|
|
|
|
7
|
|
|
use Hyde\Framework\Actions\GeneratesSidebarTableOfContents; |
|
8
|
|
|
use Hyde\Pages\Concerns\BaseMarkdownPage; |
|
9
|
|
|
use Hyde\Support\Models\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 |
|
20
|
|
|
{ |
|
21
|
|
|
use Concerns\UsesFlattenedOutputPaths; |
|
22
|
|
|
|
|
23
|
|
|
public static string $sourceDirectory = '_docs'; |
|
24
|
|
|
public static string $outputDirectory = 'docs'; |
|
25
|
|
|
public static string $template = 'hyde::layouts/docs'; |
|
26
|
|
|
|
|
27
|
|
|
public static function home(): ?Route |
|
28
|
|
|
{ |
|
29
|
|
|
return Route::get(static::homeRouteName()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public static function homeRouteName(): string |
|
33
|
|
|
{ |
|
34
|
|
|
return static::baseRouteKey().'/index'; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** @see https://hydephp.com/docs/master/documentation-pages#automatic-edit-page-button */ |
|
38
|
|
|
public function getOnlineSourcePath(): string|false |
|
39
|
|
|
{ |
|
40
|
|
|
if (config('docs.source_file_location_base') === null) { |
|
41
|
|
|
return false; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
return trim((string) config('docs.source_file_location_base'), '/').'/'.$this->identifier.'.md'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function hasTableOfContents(): bool |
|
48
|
|
|
{ |
|
49
|
|
|
return config('docs.table_of_contents.enabled', true); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Generate Table of Contents as HTML from a Markdown document body. |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getTableOfContents(): string |
|
56
|
|
|
{ |
|
57
|
|
|
return (new GeneratesSidebarTableOfContents($this->markdown))->execute(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|