Skip to content

Commit

Permalink
Add config feature to set automatic sidebar group labels
Browse files Browse the repository at this point in the history
Fixes #1467
  • Loading branch information
caendesilva committed Nov 27, 2023
1 parent d657e6d commit 576d011
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
17 changes: 17 additions & 0 deletions docs/creating-content/documentation-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,23 @@ Link items without an entry here will have fall back to the default priority of

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

### Automatic sidebar group labels

When using the automatic sidebar grouping feature (based on subdirectories), the titles of the groups are generated from the directory names.
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.
The array key is the directory name, and the value is the label.

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!

```php
// Filepath: config/docs.php
'sidebar_group_labels' => [
'questions-and-answers' => 'Questions & Answers',
],
```


### Table of contents settings

In the `config/docs.php` file you can configure the behavior, content, and the look and feel of the sidebar table of contents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 @@ -59,7 +60,7 @@ public function isGroupActive(string $group): bool

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

protected function canAddRoute(Route $route): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,16 @@ public function test_make_group_title_turns_group_key_into_title()
$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 576d011

Please sign in to comment.