1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Concerns\FrontMatter\Schemas; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
|
7
|
|
|
trait DocumentationPageSchema |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* The sidebar category group, if any. |
11
|
|
|
*/ |
12
|
|
|
public ?string $category = null; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The label for the page shown in the sidebar. |
16
|
|
|
*/ |
17
|
|
|
public ?string $label; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Hides the page from the sidebar. |
21
|
|
|
*/ |
22
|
|
|
public ?bool $hidden = null; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The priority of the page used for ordering the sidebar. |
26
|
|
|
*/ |
27
|
|
|
public ?int $priority = null; |
28
|
|
|
|
29
|
|
|
protected function constructDocumentationPageSchema(): void |
30
|
|
|
{ |
31
|
|
|
$this->category = static::getDocumentationPageCategory(); |
|
|
|
|
32
|
|
|
|
33
|
|
|
$this->hidden = $this->matter('hidden', $this->identifier === 'index'); |
|
|
|
|
34
|
|
|
$this->priority = $this->matter('priority', $this->findPriorityInConfig()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
protected function getDocumentationPageCategory(): ?string |
38
|
|
|
{ |
39
|
|
|
// If the documentation page is in a subdirectory, |
40
|
|
|
// then we can use that as the category name. |
41
|
|
|
// Otherwise, we look in the front matter. |
42
|
|
|
|
43
|
|
|
return str_contains($this->identifier, '/') |
44
|
|
|
? Str::before($this->identifier, '/') |
45
|
|
|
: $this->matter('category'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function findPriorityInConfig(): int |
49
|
|
|
{ |
50
|
|
|
$orderIndexArray = config('docs.sidebar_order', []); |
51
|
|
|
|
52
|
|
|
if (! in_array($this->identifier, $orderIndexArray)) { |
53
|
|
|
return 500; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return array_search($this->identifier, $orderIndexArray) + 250; |
57
|
|
|
|
58
|
|
|
// Adding 250 makes so that pages with a front matter priority that is lower |
59
|
|
|
// can be shown first. It's lower than the fallback of 500 so that they |
60
|
|
|
// still come first. This is all to make it easier to mix priorities. |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|