Passed
Push — master ( 6a0eb4...c7f34a )
by Caen
03:47 queued 13s
created

DocumentationPage::getDocumentationPageCategory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hyde\Framework\Models\Pages;
4
5
use Hyde\Framework\Concerns\HasTableOfContents;
6
use Hyde\Framework\Contracts\AbstractMarkdownPage;
7
use Hyde\Framework\Contracts\RouteContract;
8
use Hyde\Framework\Models\Route;
9
10
class DocumentationPage extends AbstractMarkdownPage
11
{
12
    use HasTableOfContents;
13
14
    public static string $sourceDirectory = '_docs';
15
    public static string $outputDirectory = 'docs';
16
    public static string $template = 'hyde::layouts/docs';
17
18
    /**
19
     * The sidebar category group, if any.
20
     */
21
    public ?string $category;
22
23
    public function __construct(array $matter = [], string $body = '', string $title = '', string $slug = '')
24
    {
25
        parent::__construct($matter, $body, $title, $slug);
26
    }
27
28
    /** @inheritDoc */
29
    public function getCurrentPagePath(): string
30
    {
31
        return trim(static::getOutputDirectory().'/'.basename($this->slug), '/');
32
    }
33
34
    /** @internal */
35
    public function getOnlineSourcePath(): string|false
36
    {
37
        if (config('docs.source_file_location_base') === null) {
38
            return false;
39
        }
40
41
        return trim(config('docs.source_file_location_base'), '/').'/'.$this->slug.'.md';
42
    }
43
44
    public static function home(): ?RouteContract
45
    {
46
        return Route::exists('docs/index') ? Route::get('docs/index') : null;
47
    }
48
49
    public static function hasTableOfContents(): bool
50
    {
51
        return config('docs.table_of_contents.enabled', true);
52
    }
53
}
54