-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from hydephp/create-navigation-menu-generatio…
…n-service Convert navigation menu generation to service
- Loading branch information
Showing
19 changed files
with
734 additions
and
287 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
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
11 changes: 8 additions & 3 deletions
11
packages/framework/resources/views/components/navigation/navigation-link.blade.php
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
<a href="{{ $item['route'] }}" {{ $item['current'] ? 'aria-current="page"' : '' }} | ||
@php | ||
/** @var \Hyde\Framework\Contracts\PageContract $page */ | ||
$isCurrent = $page->getRoute()->getRouteKey() === $item->route->getRouteKey(); | ||
@endphp | ||
|
||
<a href="{{ $item->resolveLink($currentPage) }}" {{ $isCurrent ? 'aria-current="page"' : '' }} | ||
@class(['block my-2 md:my-0 md:inline-block py-1 text-gray-700 hover:text-gray-900 dark:text-gray-100' | ||
, 'border-l-4 border-indigo-500 md:border-none font-medium -ml-6 pl-5 md:ml-0 md:pl-0 bg-gray-100 dark:bg-gray-800 md:bg-transparent dark:md:bg-transparent'=> $item['current'] | ||
, 'border-l-4 border-indigo-500 md:border-none font-medium -ml-6 pl-5 md:ml-0 md:pl-0 bg-gray-100 dark:bg-gray-800 md:bg-transparent dark:md:bg-transparent'=> $isCurrent | ||
])> | ||
{{ $item['title'] }} | ||
{{ $item->title }} | ||
</a> |
Empty file.
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
188 changes: 0 additions & 188 deletions
188
packages/framework/src/Actions/GeneratesNavigationMenu.php
This file was deleted.
Oops, something went wrong.
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,118 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework\Concerns; | ||
|
||
use Hyde\Framework\Contracts\AbstractMarkdownPage; | ||
use Hyde\Framework\Hyde; | ||
use Hyde\Framework\Models\Pages\DocumentationPage; | ||
use Hyde\Framework\Models\Pages\MarkdownPost; | ||
|
||
/** | ||
* Offloads logic related to navigation menu items for AbstractPage classes. | ||
* | ||
* @see \Hyde\Framework\Testing\Feature\Concerns\CanBeInNavigationTest | ||
*/ | ||
trait CanBeInNavigation | ||
{ | ||
/** | ||
* Should the item should be displayed in the navigation menu? | ||
* | ||
* @return bool | ||
*/ | ||
public function showInNavigation(): bool | ||
{ | ||
if ($this instanceof MarkdownPost) { | ||
return false; | ||
} | ||
|
||
if ($this instanceof DocumentationPage) { | ||
return $this->slug === 'index'; | ||
} | ||
|
||
if ($this instanceof AbstractMarkdownPage) { | ||
if ($this->markdown->matter('navigation.hidden', false)) { | ||
return false; | ||
} | ||
} | ||
|
||
if (in_array($this->slug, config('hyde.navigation.exclude', ['404']))) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* The relative priority, determining the position of the item in the menu. | ||
* | ||
* @return int | ||
*/ | ||
public function navigationMenuPriority(): int | ||
{ | ||
if ($this instanceof AbstractMarkdownPage) { | ||
if ($this->matter('navigation.priority') !== null) { | ||
return $this->matter('navigation.priority'); | ||
} | ||
} | ||
|
||
if (array_key_exists($this->slug, config('hyde.navigation.order', []))) { | ||
return (int) config('hyde.navigation.order.'.$this->slug); | ||
} | ||
|
||
if ($this instanceof DocumentationPage) { | ||
return 100; | ||
} | ||
|
||
if ($this->slug === 'index') { | ||
return 0; | ||
} | ||
|
||
if ($this->slug === 'posts') { | ||
return 10; | ||
} | ||
|
||
return 1000; | ||
} | ||
|
||
/** | ||
* The page title to display in the navigation menu. | ||
* | ||
* @return string | ||
*/ | ||
public function navigationMenuTitle(): string | ||
{ | ||
if ($this instanceof AbstractMarkdownPage) { | ||
if ($this->matter('navigation.title') !== null) { | ||
return $this->matter('navigation.title'); | ||
} | ||
|
||
if ($this->matter('title') !== null) { | ||
return $this->matter('title'); | ||
} | ||
} | ||
|
||
if ($this->slug === 'index') { | ||
if ($this instanceof DocumentationPage) { | ||
return 'Docs'; | ||
} | ||
|
||
return 'Home'; | ||
} | ||
|
||
if (isset($this->title) && ! blank($this->title)) { | ||
return $this->title; | ||
} | ||
|
||
return Hyde::makeTitle($this->slug); | ||
} | ||
|
||
/** | ||
* Not yet implemented. | ||
* | ||
* If an item returns a route collection, | ||
* it will automatically be made into a dropdown. | ||
* | ||
* @return \Illuminate\Support\Collection<\Hyde\Framework\Modules\Routing\Route> | ||
*/ | ||
// public function navigationMenuChildren(): Collection; | ||
} |
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
Oops, something went wrong.