From 28355843809293041f4422ff4d2085abc4f94ffe Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 26 Nov 2023 16:32:37 +0000 Subject: [PATCH 1/2] Merge pull request #1472 from hydephp/add-documentation-index-page-to-sidebar-when-it-is-the-only-page Add documentation index page to the sidebar when it's the only page https://github.com/hydephp/develop/commit/a524c176bf569fdc6949dd5f43c3ca94ca564797 --- .../Navigation/DocumentationSidebar.php | 5 ++++ .../Services/DocumentationSidebarTest.php | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Framework/Features/Navigation/DocumentationSidebar.php b/src/Framework/Features/Navigation/DocumentationSidebar.php index ebbe5112..6cf239a9 100644 --- a/src/Framework/Features/Navigation/DocumentationSidebar.php +++ b/src/Framework/Features/Navigation/DocumentationSidebar.php @@ -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 diff --git a/tests/Feature/Services/DocumentationSidebarTest.php b/tests/Feature/Services/DocumentationSidebarTest.php index b1cadcbd..9ac37522 100644 --- a/tests/Feature/Services/DocumentationSidebarTest.php +++ b/tests/Feature/Services/DocumentationSidebarTest.php @@ -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++) { From 799f8e47b859775ef128d4f4f4e5ed3385cee22c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sun, 26 Nov 2023 17:38:01 +0100 Subject: [PATCH 2/2] Version v1.3.4 --- src/Foundation/HydeKernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Foundation/HydeKernel.php b/src/Foundation/HydeKernel.php index c15f68b2..8a9df59f 100644 --- a/src/Foundation/HydeKernel.php +++ b/src/Foundation/HydeKernel.php @@ -49,7 +49,7 @@ class HydeKernel implements SerializableContract use Serializable; use Macroable; - final public const VERSION = '1.3.3'; + final public const VERSION = '1.3.4'; protected static self $instance;