Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| DocumentationPage | |
100.00% |
13 / 13 |
|
100.00% |
7 / 7 |
10 | |
100.00% |
1 / 1 |
| home | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| homeRouteName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOnlineSourcePath | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| hasTableOfContents | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getTableOfContents | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRouteKey | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| getOutputPath | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Hyde\Pages; |
| 6 | |
| 7 | use Hyde\Facades\Config; |
| 8 | use Hyde\Foundation\Facades\Routes; |
| 9 | use Hyde\Framework\Actions\GeneratesTableOfContents; |
| 10 | use Hyde\Pages\Concerns\BaseMarkdownPage; |
| 11 | use Hyde\Support\Models\Route; |
| 12 | |
| 13 | use function trim; |
| 14 | use function sprintf; |
| 15 | use function Hyde\unslash; |
| 16 | use function basename; |
| 17 | |
| 18 | /** |
| 19 | * Page class for documentation pages. |
| 20 | * |
| 21 | * Documentation pages are stored in the _docs directory and using the .md extension. |
| 22 | * The Markdown will be compiled to HTML using the documentation page layout to the _site/docs/ directory. |
| 23 | * |
| 24 | * @see https://hydephp.com/docs/1.x/documentation-pages |
| 25 | */ |
| 26 | class DocumentationPage extends BaseMarkdownPage |
| 27 | { |
| 28 | public static string $sourceDirectory = '_docs'; |
| 29 | public static string $outputDirectory = 'docs'; |
| 30 | public static string $template = 'hyde::layouts/docs'; |
| 31 | |
| 32 | public static function home(): ?Route |
| 33 | { |
| 34 | return Routes::get(static::homeRouteName()); |
| 35 | } |
| 36 | |
| 37 | public static function homeRouteName(): string |
| 38 | { |
| 39 | return unslash(static::baseRouteKey().'/index'); |
| 40 | } |
| 41 | |
| 42 | /** @see https://hydephp.com/docs/1.x/documentation-pages#automatic-edit-page-button */ |
| 43 | public function getOnlineSourcePath(): string|false |
| 44 | { |
| 45 | if (Config::getNullableString('docs.source_file_location_base') === null) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | return sprintf('%s/%s.md', trim(Config::getString('docs.source_file_location_base'), '/'), $this->identifier); |
| 50 | } |
| 51 | |
| 52 | public static function hasTableOfContents(): bool |
| 53 | { |
| 54 | return Config::getBool('docs.table_of_contents.enabled', true); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Generate Table of Contents as HTML from a Markdown document body. |
| 59 | */ |
| 60 | public function getTableOfContents(): string |
| 61 | { |
| 62 | return (new GeneratesTableOfContents($this->markdown))->execute(); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get the route key for the page. |
| 67 | * |
| 68 | * If flattened outputs are enabled, this will use the identifier basename so nested pages are flattened. |
| 69 | */ |
| 70 | public function getRouteKey(): string |
| 71 | { |
| 72 | return Config::getBool('docs.flattened_output_paths', true) |
| 73 | ? unslash(static::outputDirectory().'/'.basename($this->identifier)) |
| 74 | : parent::getRouteKey(); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get the path where the compiled page will be saved. |
| 79 | * |
| 80 | * If flattened outputs are enabled, this will use the identifier basename so nested pages are flattened. |
| 81 | */ |
| 82 | public function getOutputPath(): string |
| 83 | { |
| 84 | return Config::getBool('docs.flattened_output_paths', true) |
| 85 | ? static::outputPath(basename($this->identifier)) |
| 86 | : parent::getOutputPath(); |
| 87 | } |
| 88 | } |