Passed
Push — master ( c6d817...cca966 )
by Caen
03:03 queued 12s
created

DocumentationPage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 56
rs 10
c 5
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getOnlineSourcePath() 0 7 2
A getTableOfContents() 0 3 1
A __construct() 0 3 1
A hasTableOfContents() 0 3 1
A home() 0 3 2
A getRouteKey() 0 3 1
1
<?php
2
3
namespace Hyde\Framework\Models\Pages;
4
5
use Hyde\Framework\Actions\GeneratesSidebarTableOfContents;
6
use Hyde\Framework\Concerns\AbstractMarkdownPage;
7
use Hyde\Framework\Contracts\FrontMatter\DocumentationPageSchema;
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 implements DocumentationPageSchema
14
{
15
    public static string $sourceDirectory = '_docs';
16
    public static string $outputDirectory = 'docs';
17
    public static string $template = 'hyde::layouts/docs';
18
19
    /** The sidebar category group, if any. Can be overridden in front matter, or by putting the source file in a subdirectory of the same category name. */
20
    public ?string $category = null;
21
22
    /** The label for the page shown in the sidebar. */
23
    public ?string $label = null;
24
25
    /** Hides the page from the sidebar. */
26
    public ?bool $hidden = null;
27
28
    /** The priority of the page used for ordering the sidebar. */
29
    public ?int $priority = null;
30
31
    /** @inheritDoc */
32
    public function __construct(string $identifier = '', ?FrontMatter $matter = null, ?Markdown $markdown = null)
33
    {
34
        parent::__construct($identifier, $matter, $markdown);
35
    }
36
37
    /** @inheritDoc */
38
    public function getRouteKey(): string
39
    {
40
        return trim(static::getOutputDirectory().'/'.basename($this->identifier), '/');
41
    }
42
43
    /** @internal */
44
    public function getOnlineSourcePath(): string|false
45
    {
46
        if (config('docs.source_file_location_base') === null) {
47
            return false;
48
        }
49
50
        return trim(config('docs.source_file_location_base'), '/').'/'.$this->identifier.'.md';
51
    }
52
53
    public static function home(): ?RouteContract
54
    {
55
        return Route::exists(static::$outputDirectory.'/index') ? Route::get(static::$outputDirectory.'/index') : null;
56
    }
57
58
    public static function hasTableOfContents(): bool
59
    {
60
        return config('docs.table_of_contents.enabled', true);
61
    }
62
63
    /**
64
     * Generate Table of Contents as HTML from a Markdown document body.
65
     */
66
    public function getTableOfContents(): string
67
    {
68
        return (new GeneratesSidebarTableOfContents($this->markdown))->execute();
69
    }
70
}
71