Skip to content

Commit

Permalink
Merge pull request #1481 from hydephp/customizable-automatic-sidebar-…
Browse files Browse the repository at this point in the history
…navigation-group-names

Add config option to customize automatic sidebar navigation group names hydephp/develop@108ba0f
  • Loading branch information
github-actions committed Nov 27, 2023
1 parent 8943332 commit 20276a1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/views/components/docs/sidebar-items.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@foreach ($sidebar->getGroups() as $group)
<li class="sidebar-group" role="listitem" @if($collapsible) x-data="{ groupOpen: {{ $sidebar->isGroupActive($group) ? 'true' : 'false' }} }" @endif>
<header class="sidebar-group-header p-2 px-4 -ml-2 flex justify-between items-center @if($collapsible) group hover:bg-black/10 @endif" @if($collapsible) @click="groupOpen = ! groupOpen" @endif>
<h4 class="sidebar-group-heading text-base font-semibold @if($collapsible) cursor-pointer dark:group-hover:text-white @endif">{{ Hyde::makeTitle($group) }}</h4>
<h4 class="sidebar-group-heading text-base font-semibold @if($collapsible) cursor-pointer dark:group-hover:text-white @endif">{{ $sidebar->makeGroupTitle($group) }}</h4>
@if($collapsible)
@include('hyde::components.docs.sidebar-group-toggle-button')
@endif
Expand Down
7 changes: 7 additions & 0 deletions src/Framework/Features/Navigation/DocumentationSidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Hyde\Framework\Features\Navigation;

use Hyde\Hyde;
use Hyde\Facades\Config;
use Hyde\Foundation\Facades\Routes;
use Hyde\Pages\DocumentationPage;
use Hyde\Support\Facades\Render;
Expand Down Expand Up @@ -56,6 +58,11 @@ public function isGroupActive(string $group): bool
|| $this->isPageIndexPage() && $this->shouldIndexPageBeActive($group);
}

public function makeGroupTitle(string $group): string
{
return Config::getNullableString("docs.sidebar_group_labels.$group") ?? Hyde::makeTitle($group);
}

protected function canAddRoute(Route $route): bool
{
return parent::canAddRoute($route) && ! $route->is(DocumentationPage::homeRouteName());
Expand Down
18 changes: 18 additions & 0 deletions tests/Feature/Services/DocumentationSidebarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,24 @@ public function test_automatic_index_page_group_expansion_respects_custom_naviga
$this->assertTrue(DocumentationSidebar::create()->isGroupActive('baz'));
}

public function test_make_group_title_turns_group_key_into_title()
{
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('hello world'));
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('hello-world'));
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('hello_world'));
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('helloWorld'));
}

public function test_make_group_title_uses_configured_sidebar_group_labels_when_available()
{
Config::set('docs.sidebar_group_labels', [
'example' => 'Hello world!',
]);

$this->assertSame('Hello world!', DocumentationSidebar::create()->makeGroupTitle('example'));
$this->assertSame('Default', DocumentationSidebar::create()->makeGroupTitle('default'));
}

public function test_can_have_multiple_grouped_pages_with_the_same_name_labels()
{
$this->makePage('foo', ['navigation.group' => 'foo', 'navigation.label' => 'Foo']);
Expand Down

0 comments on commit 20276a1

Please sign in to comment.