Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation index page to the sidebar when it's the only page #1472

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 @@ -22,6 +22,11 @@ protected function generate(): void
$this->items->put($route->getRouteKey(), NavItem::fromRoute($route));
}
});

// 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'));
}
}

public function hasGroups(): bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,31 @@ public function test_is_group_active_for_index_page_with_no_groups()
$this->assertFalse(DocumentationSidebar::create()->isGroupActive('foo'));
}

public function test_index_page_added_to_sidebar_when_it_is_the_only_page()
{
Filesystem::touch('_docs/index.md');
$sidebar = DocumentationSidebar::create();

$this->assertCount(1, $sidebar->items);
$this->assertEquals(
collect([NavItem::fromRoute(Routes::get('docs/index'))]),
$sidebar->items
);
}

public function test_index_page_not_added_to_sidebar_when_other_pages_exist()
{
$this->createTestFiles(1);
Filesystem::touch('_docs/index.md');
$sidebar = DocumentationSidebar::create();

$this->assertCount(1, $sidebar->items);
$this->assertEquals(
collect([NavItem::fromRoute(Routes::get('docs/test-0'))]),
$sidebar->items
);
}

protected function createTestFiles(int $count = 5): void
{
for ($i = 0; $i < $count; $i++) {
Expand Down
Loading