Skip to content

Commit 6dd3cd7

Browse files
authored
Merge pull request #974 from hydephp/create-helper-to-get-the-documentation-page-home-route-name
Create helper to get the documentation page home route name
2 parents c3febd1 + 392c900 commit 6dd3cd7

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

packages/framework/src/Framework/Factories/NavigationDataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function searchForLabelInConfig(): ?string
131131
{
132132
return Arr::get(config('hyde.navigation.labels', [
133133
'index' => 'Home',
134-
'docs/index' => 'Docs',
134+
DocumentationPage::homeRouteName() => 'Docs',
135135
]), $this->routeKey);
136136
}
137137

packages/framework/src/Framework/Features/Navigation/DocumentationSidebar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public function getItemsInGroup(?string $group): Collection
4646

4747
protected static function shouldItemBeHidden(NavItem $item): bool
4848
{
49-
return parent::shouldItemBeHidden($item) || $item->getRoute()?->is('docs/index');
49+
return parent::shouldItemBeHidden($item) || $item->getRoute()?->is(DocumentationPage::homeRouteName());
5050
}
5151
}

packages/framework/src/Framework/Features/Navigation/NavigationMenu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ protected static function dropdownsEnabled(): bool
8181
protected static function shouldItemBeHidden(NavItem $item): bool
8282
{
8383
return parent::shouldItemBeHidden($item) ||
84-
$item->getRoute()?->getPage() instanceof DocumentationPage && ! $item->getRoute()->is('docs/index');
84+
$item->getRoute()?->getPage() instanceof DocumentationPage && ! $item->getRoute()->is(DocumentationPage::homeRouteName());
8585
}
8686
}

packages/framework/src/Pages/DocumentationPage.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ class DocumentationPage extends BaseMarkdownPage
2626

2727
public static function home(): ?Route
2828
{
29-
return Route::get(static::$outputDirectory.'/index');
29+
return Route::get(static::homeRouteName());
30+
}
31+
32+
public static function homeRouteName(): string
33+
{
34+
return static::baseRouteKey().'/index';
3035
}
3136

3237
/** @see https://hydephp.com/docs/master/documentation-pages#automatic-edit-page-button */

packages/framework/tests/Unit/DocumentationPageTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ public function test_home_method_finds_docs_index_for_custom_nested_output_direc
144144
File::deleteDirectory(Hyde::path('foo'));
145145
}
146146

147+
public function test_home_route_name_method_returns_output_directory_slash_index()
148+
{
149+
$this->assertSame('docs/index', DocumentationPage::homeRouteName());
150+
}
151+
152+
public function test_home_route_name_method_returns_customized_output_directory_slash_index()
153+
{
154+
config(['docs.output_directory' => 'foo/bar']);
155+
(new HydeServiceProvider($this->app))->register();
156+
157+
$this->assertSame('foo/bar/index', DocumentationPage::homeRouteName());
158+
}
159+
147160
public function test_has_table_of_contents()
148161
{
149162
$this->assertIsBool(DocumentationPage::hasTableOfContents());

0 commit comments

Comments
 (0)