Skip to content

Commit 108ba0f

Browse files
authored
Merge pull request #1481 from hydephp/customizable-automatic-sidebar-navigation-group-names
Add config option to customize automatic sidebar navigation group names
2 parents 48e02b8 + 09a587a commit 108ba0f

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This serves two purposes:
1212
### Added
1313
- Adds a new fancy output for the realtime compiler serve command in https://github.com/hydephp/develop/pull/1444
1414
- Added support for dot notation in the Yaml configuration files in https://github.com/hydephp/develop/pull/1478
15+
- Added a config option to customize automatic sidebar navigation group names in https://github.com/hydephp/develop/pull/1481
1516

1617
### Changed
1718
- The `docs.sidebar.footer` config option now accepts a Markdown string to replace the default footer in https://github.com/hydephp/develop/pull/1477

docs/creating-content/documentation-pages.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,23 @@ Link items without an entry here will have fall back to the default priority of
234234

235235
See [the chapter in the customization page](customization#navigation-menu--sidebar) for more details. <br>
236236

237+
### Automatic sidebar group labels
238+
239+
When using the automatic sidebar grouping feature (based on subdirectories), the titles of the groups are generated from the directory names.
240+
If these are not to your liking, for example if you need to use special characters, you can override them in the Docs configuration file.
241+
The array key is the directory name, and the value is the label.
242+
243+
Please note that this option is not added to the config file by default, as it's not a super common use case. No worries though, just add the following yourself!
244+
245+
```php
246+
// Filepath: config/docs.php
247+
248+
'sidebar_group_labels' => [
249+
'questions-and-answers' => 'Questions & Answers',
250+
],
251+
```
252+
253+
237254
### Table of contents settings
238255

239256
In the `config/docs.php` file you can configure the behavior, content, and the look and feel of the sidebar table of contents.

packages/framework/resources/views/components/docs/sidebar-items.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@foreach ($sidebar->getGroups() as $group)
1212
<li class="sidebar-group" role="listitem" @if($collapsible) x-data="{ groupOpen: {{ $sidebar->isGroupActive($group) ? 'true' : 'false' }} }" @endif>
1313
<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>
14-
<h4 class="sidebar-group-heading text-base font-semibold @if($collapsible) cursor-pointer dark:group-hover:text-white @endif">{{ Hyde::makeTitle($group) }}</h4>
14+
<h4 class="sidebar-group-heading text-base font-semibold @if($collapsible) cursor-pointer dark:group-hover:text-white @endif">{{ $sidebar->makeGroupTitle($group) }}</h4>
1515
@if($collapsible)
1616
@include('hyde::components.docs.sidebar-group-toggle-button')
1717
@endif

packages/framework/src/Framework/Features/Navigation/DocumentationSidebar.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Hyde\Framework\Features\Navigation;
66

7+
use Hyde\Hyde;
8+
use Hyde\Facades\Config;
79
use Hyde\Foundation\Facades\Routes;
810
use Hyde\Pages\DocumentationPage;
911
use Hyde\Support\Facades\Render;
@@ -56,6 +58,11 @@ public function isGroupActive(string $group): bool
5658
|| $this->isPageIndexPage() && $this->shouldIndexPageBeActive($group);
5759
}
5860

61+
public function makeGroupTitle(string $group): string
62+
{
63+
return Config::getNullableString("docs.sidebar_group_labels.$group") ?? Hyde::makeTitle($group);
64+
}
65+
5966
protected function canAddRoute(Route $route): bool
6067
{
6168
return parent::canAddRoute($route) && ! $route->is(DocumentationPage::homeRouteName());

packages/framework/tests/Feature/Services/DocumentationSidebarTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,24 @@ public function test_automatic_index_page_group_expansion_respects_custom_naviga
337337
$this->assertTrue(DocumentationSidebar::create()->isGroupActive('baz'));
338338
}
339339

340+
public function test_make_group_title_turns_group_key_into_title()
341+
{
342+
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('hello world'));
343+
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('hello-world'));
344+
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('hello_world'));
345+
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('helloWorld'));
346+
}
347+
348+
public function test_make_group_title_uses_configured_sidebar_group_labels_when_available()
349+
{
350+
Config::set('docs.sidebar_group_labels', [
351+
'example' => 'Hello world!',
352+
]);
353+
354+
$this->assertSame('Hello world!', DocumentationSidebar::create()->makeGroupTitle('example'));
355+
$this->assertSame('Default', DocumentationSidebar::create()->makeGroupTitle('default'));
356+
}
357+
340358
public function test_can_have_multiple_grouped_pages_with_the_same_name_labels()
341359
{
342360
$this->makePage('foo', ['navigation.group' => 'foo', 'navigation.label' => 'Foo']);

0 commit comments

Comments
 (0)