Passed
Push — master ( c3febd...6dd3cd )
by Caen
03:27 queued 12s
created

DocumentationPage::hasTableOfContents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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