1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Concerns\FrontMatter\Schemas\Constructors; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Hyde; |
6
|
|
|
use Illuminate\Support\Str; |
7
|
|
|
|
8
|
|
|
trait DocumentationPageSchemaConstructor |
9
|
|
|
{ |
10
|
|
|
protected function constructDocumentationPageSchema(): void |
11
|
|
|
{ |
12
|
|
|
$this->category = $this->getDocumentationPageCategory(); |
|
|
|
|
13
|
|
|
|
14
|
|
|
$this->label = $this->matter('label', Hyde::makeTitle(basename($this->identifier))); |
|
|
|
|
15
|
|
|
$this->hidden = $this->matter('hidden', $this->identifier === 'index'); |
|
|
|
|
16
|
|
|
$this->priority = $this->matter('priority', $this->findPriorityInConfig()); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function getDocumentationPageCategory(): ?string |
20
|
|
|
{ |
21
|
|
|
// If the documentation page is in a subdirectory, |
22
|
|
|
// then we can use that as the category name. |
23
|
|
|
// Otherwise, we look in the front matter. |
24
|
|
|
|
25
|
|
|
return str_contains($this->identifier, '/') |
26
|
|
|
? Str::before($this->identifier, '/') |
27
|
|
|
: $this->matter('category', 'other'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
protected function findPriorityInConfig(): int |
31
|
|
|
{ |
32
|
|
|
$orderIndexArray = config('docs.sidebar_order', []); |
33
|
|
|
|
34
|
|
|
if (! in_array($this->identifier, $orderIndexArray)) { |
35
|
|
|
return 500; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return array_search($this->identifier, $orderIndexArray) + 250; |
39
|
|
|
|
40
|
|
|
// Adding 250 makes so that pages with a front matter priority that is lower |
41
|
|
|
// can be shown first. It's lower than the fallback of 500 so that they |
42
|
|
|
// still come first. This is all to make it easier to mix priorities. |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|