Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function makeGroup(): ?string
return $this->getSubdirectoryName();
}

return $this->searchForGroupInFrontMatter() ?? $this->defaultGroup();
return $this->searchForGroupInFrontMatter();
}

protected function makeHidden(): bool
Expand Down Expand Up @@ -208,12 +208,6 @@ private function canUseSubdirectoryForGroups(): bool
|| $this->isInstanceOf(DocumentationPage::class);
}

private function defaultGroup(): ?string
{
// TODO: It would be better if this was null in all cases, considering 'other' is used a a sort of confusing pseudo-null
return $this->isInstanceOf(DocumentationPage::class) ? 'other' : null;
}

private function pageIsInSubdirectory(): bool
{
return Str::contains($this->identifier, '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public static function create(): static

public function hasGroups(): bool
{
return (count($this->getGroups()) >= 1) && ($this->getGroups() !== ['other']);
return (count($this->getGroups()) >= 1) && ($this->getGroups() !== [null]);
}

/** @return array<string> */
public function getGroups(): array
{
return $this->items->map(function (NavItem $item): string {
return $this->items->map(function (NavItem $item): ?string {
return $item->getGroup();
})->unique()->toArray();
}
Expand All @@ -64,8 +64,12 @@ public function getItemsInGroup(?string $group): Collection
*
* For index pages, this will also return true for the first group in the menu, unless the index page has a specific group set.
*/
public function isGroupActive(string $group): bool
public function isGroupActive(?string $group): bool
{
if ($group === null) {
return false;
}

$groupMatchesCurrentPageGroup = Str::slug(Render::getPage()->navigationMenuGroup()) === $group;
$currentPageIsIndexPageAndShouldBeActive = $this->isPageIndexPage() && $this->shouldIndexPageBeActive($group);

Expand All @@ -77,9 +81,9 @@ public function isGroupActive(string $group): bool
*
* @todo Get title from instance
*/
public function makeGroupTitle(string $group): string
public function makeGroupTitle(?string $group): string
{
return Config::getNullableString("docs.sidebar_group_labels.$group") ?? Hyde::makeTitle($group);
return Config::getNullableString("docs.sidebar_group_labels.$group") ?? Hyde::makeTitle($group ?? 'Other');
}

private function isPageIndexPage(): bool
Expand All @@ -89,7 +93,7 @@ private function isPageIndexPage(): bool

private function shouldIndexPageBeActive(string $group): bool
{
$indexPageHasNoSetGroup = Render::getPage()->navigationMenuGroup() === 'other';
$indexPageHasNoSetGroup = Render::getPage()->navigationMenuGroup() === null;
$groupIsTheFirstOneInSidebar = $group === collect($this->getGroups())->first();

return $indexPageHasNoSetGroup && $groupIsTheFirstOneInSidebar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function generate(): void

// If there are no pages other than the index page, we add it to the sidebar so that it's not empty
if ($this->items->count() === 0 && DocumentationPage::home() !== null) {
$this->items->push(NavItem::fromRoute(DocumentationPage::home(), group: 'other'));
$this->items->push(NavItem::fromRoute(DocumentationPage::home(), group: null));
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/framework/tests/Feature/HydePageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function testNavigationMenuGroup()
$this->assertNull((new MarkdownPage())->navigationMenuGroup());
$this->assertNull((new MarkdownPost())->navigationMenuGroup());
$this->assertNull((new HtmlPage())->navigationMenuGroup());
$this->assertSame('other', (new DocumentationPage())->navigationMenuGroup());
$this->assertNull((new DocumentationPage())->navigationMenuGroup());
$this->assertSame('foo', DocumentationPage::make(matter: ['navigation' => ['group' => 'foo']])->navigationMenuGroup());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ public function testJsonSerializedDocumentationPageContents()
"label": "",
"priority": 999,
"hidden": false,
"group": "other"
"group": null
},
"title": ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testNavigationMenuLabel()

public function testNavigationMenuGroup()
{
$this->assertSame('other', (new DocumentationPage('foo'))->navigationMenuGroup());
$this->assertSame(null, (new DocumentationPage('foo'))->navigationMenuGroup());
}

public function testNavigationMenuGroupWithData()
Expand Down