Passed
Push — master ( 47a9f8...ac7470 )
by Caen
03:47 queued 12s
created

DocumentationPage::getCurrentPagePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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 = '', ?string $category = null)
24
    {
25
        parent::__construct($matter, $body, $title, $slug);
26
        $this->category = $category;
27
    }
28
29
    /** @inheritDoc */
30
    public function getCurrentPagePath(): string
31
    {
32
        return trim(static::getOutputDirectory().'/'.basename($this->slug), '/');
33
    }
34
35
    /** @internal */
36
    public function getOnlineSourcePath(): string|false
37
    {
38
        if (config('docs.source_file_location_base') === null) {
39
            return false;
40
        }
41
42
        return trim(config('docs.source_file_location_base'), '/').'/'.$this->slug.'.md';
43
    }
44
45
    public static function home(): ?RouteContract
46
    {
47
        return Route::exists('docs/index') ? Route::get('docs/index') : null;
48
    }
49
50
    public static function hasTableOfContents(): bool
51
    {
52
        return config('docs.table_of_contents.enabled', true);
53
    }
54
}
55