-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb3c337
commit fbcae7c
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework\Models; | ||
|
||
use Hyde\Framework\Contracts\DocumentationSidebarContract; | ||
use Illuminate\Support\Collection; | ||
|
||
/** | ||
* The documentation sidebar, containing all the sidebar items. | ||
* | ||
* Extends the Illuminate\Support\Collection class and has helper | ||
* methods to fluently add DocumentationSidebarItems to the | ||
* collection using method chaining. | ||
* | ||
* @see \Tests\Feature\Services\DocumentationSidebarServiceTest | ||
*/ | ||
class DocumentationSidebar extends Collection implements DocumentationSidebarContract | ||
{ | ||
public function addItem(DocumentationSidebarItem $item): self | ||
{ | ||
$this->push($item); | ||
|
||
return $this; | ||
} | ||
|
||
public function sortItems(): self | ||
{ | ||
return $this->sortBy('priority') | ||
->values(); // Reset the keys to consecutively numbered indexes: | ||
} | ||
|
||
public function getCollection(): self | ||
{ | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework\Models; | ||
|
||
use Hyde\Framework\Hyde; | ||
use Spatie\YamlFrontMatter\YamlFrontMatter; | ||
|
||
/** | ||
* Object containing information for a sidebar item. | ||
* | ||
* @see \Tests\Feature\Services\DocumentationSidebarServiceTest | ||
*/ | ||
class DocumentationSidebarItem | ||
{ | ||
public string $label; | ||
public string $destination; | ||
public int $priority; | ||
|
||
public function __construct(string $label, string $destination, ?int $priority = null) | ||
{ | ||
$this->label = $label; | ||
$this->destination = $destination; | ||
$this->priority = $priority ?? $this->findPriorityInConfig($destination); | ||
} | ||
|
||
protected function findPriorityInConfig(string $slug): int | ||
{ | ||
$orderIndexArray = config('hyde.documentationPageOrder', []); | ||
|
||
if (! in_array($slug, $orderIndexArray)) { | ||
return 500; | ||
} | ||
|
||
return array_search($slug, $orderIndexArray); // + 250? | ||
} | ||
|
||
public static function parseFromFile(string $documentationPageSlug): static | ||
{ | ||
$matter = YamlFrontMatter::markdownCompatibleParse( | ||
file_get_contents(Hyde::path('_docs/' . $documentationPageSlug . '.md')) | ||
)->matter(); | ||
|
||
return new static( | ||
$matter['label'] ?? Hyde::titleFromSlug($documentationPageSlug), | ||
$documentationPageSlug, | ||
$matter['priority'] ?? null | ||
); | ||
} | ||
} |