File tree 2 files changed +30
-0
lines changed
src/Framework/Features/Navigation
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,11 @@ protected function generate(): void
22
22
$ this ->items ->put ($ route ->getRouteKey (), NavItem::fromRoute ($ route ));
23
23
}
24
24
});
25
+
26
+ // If there are no pages other than the index page, we add it to the sidebar so that it's not empty
27
+ if ($ this ->items ->count () === 0 && DocumentationPage::home () !== null ) {
28
+ $ this ->items ->push (NavItem::fromRoute (DocumentationPage::home (), group: 'other ' ));
29
+ }
25
30
}
26
31
27
32
public function hasGroups (): bool
Original file line number Diff line number Diff line change @@ -376,6 +376,31 @@ public function test_is_group_active_for_index_page_with_no_groups()
376
376
$ this ->assertFalse (DocumentationSidebar::create ()->isGroupActive ('foo ' ));
377
377
}
378
378
379
+ public function test_index_page_added_to_sidebar_when_it_is_the_only_page ()
380
+ {
381
+ Filesystem::touch ('_docs/index.md ' );
382
+ $ sidebar = DocumentationSidebar::create ();
383
+
384
+ $ this ->assertCount (1 , $ sidebar ->items );
385
+ $ this ->assertEquals (
386
+ collect ([NavItem::fromRoute (Routes::get ('docs/index ' ))]),
387
+ $ sidebar ->items
388
+ );
389
+ }
390
+
391
+ public function test_index_page_not_added_to_sidebar_when_other_pages_exist ()
392
+ {
393
+ $ this ->createTestFiles (1 );
394
+ Filesystem::touch ('_docs/index.md ' );
395
+ $ sidebar = DocumentationSidebar::create ();
396
+
397
+ $ this ->assertCount (1 , $ sidebar ->items );
398
+ $ this ->assertEquals (
399
+ collect ([NavItem::fromRoute (Routes::get ('docs/test-0 ' ))]),
400
+ $ sidebar ->items
401
+ );
402
+ }
403
+
379
404
protected function createTestFiles (int $ count = 5 ): void
380
405
{
381
406
for ($ i = 0 ; $ i < $ count ; $ i ++) {
You can’t perform that action at this time.
0 commit comments