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 cc4cb1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
16 changes: 16 additions & 0 deletions docs/creating-content/documentation-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,22 @@ 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, 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 cc4cb1d

Please sign in to comment.