Passed
Push — master ( 00b783...b7fb13 )
by Caen
03:02 queued 11s
created

DocumentationPage::getCurrentPagePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
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\FrontMatter\Schemas\DocumentationPageSchema;
6
use Hyde\Framework\Concerns\HasTableOfContents;
7
use Hyde\Framework\Contracts\AbstractMarkdownPage;
8
use Hyde\Framework\Contracts\RouteContract;
9
use Hyde\Framework\Models\FrontMatter;
10
use Hyde\Framework\Models\Markdown;
11
use Hyde\Framework\Models\Route;
12
13
class DocumentationPage extends AbstractMarkdownPage
14
{
15
    use DocumentationPageSchema;
16
    use HasTableOfContents;
17
18
    public static string $sourceDirectory = '_docs';
19
    public static string $outputDirectory = 'docs';
20
    public static string $template = 'hyde::layouts/docs';
21
22
    /** @inheritDoc */
23
    public function __construct(string $identifier = '', ?FrontMatter $matter = null, ?Markdown $markdown = null)
24
    {
25
        parent::__construct($identifier, $matter, $markdown);
26
27
        $this->constructDocumentationPageSchema();
28
    }
29
30
    /** @inheritDoc */
31
    public function getCurrentPagePath(): string
32
    {
33
        return trim(static::getOutputDirectory().'/'.basename($this->identifier), '/');
34
    }
35
36
    /** @internal */
37
    public function getOnlineSourcePath(): string|false
38
    {
39
        if (config('docs.source_file_location_base') === null) {
40
            return false;
41
        }
42
43
        return trim(config('docs.source_file_location_base'), '/').'/'.$this->identifier.'.md';
44
    }
45
46
    public static function home(): ?RouteContract
47
    {
48
        return Route::exists('docs/index') ? Route::get('docs/index') : null;
49
    }
50
51
    public static function hasTableOfContents(): bool
52
    {
53
        return config('docs.table_of_contents.enabled', true);
54
    }
55
}
56