Skip to content

Commit 53854b5

Browse files
author
github-actions
committed
Merge pull request #289 from hydephp/replace-documentation-index-path-helper
Replace deprecated documentation indexPath() helper hydephp/develop@2287419
1 parent 627627e commit 53854b5

File tree

4 files changed

+21
-100
lines changed

4 files changed

+21
-100
lines changed

resources/views/layouts/docs.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class="bg-white dark:bg-gray-900 dark:text-white min-h-screen w-screen relative
1818
class="bg-white dark:bg-gray-800 md:hidden flex justify-between w-full h-16 z-40 fixed left-0 top-0 p-4 leading-8 shadow-lg">
1919
<strong class="px-2 mr-auto">
2020
@if(Route::exists('docs/index'))
21-
<a href="{{ Route::get('docs/index') }}">
21+
<a href="{{ DocumentationPage::home() }}">
2222
{{ config('docs.header_title', 'Documentation') }}
2323
</a>
2424
@else
@@ -47,7 +47,7 @@ class="bg-gray-100 dark:bg-gray-800 dark:text-gray-200 h-screen w-64 fixed z-30
4747
<div id="sidebar-brand" class="flex items-center justify-between h-16 py-4 px-2">
4848
<strong class="px-2">
4949
@if(Route::exists('docs/index'))
50-
<a href="{{ Route::get('docs/index') }}">
50+
<a href="{{ DocumentationPage::home() }}">
5151
{{ config('docs.header_title', 'Documentation') }}
5252
</a>
5353
@else

src/Models/Pages/DocumentationPage.php

+4-22
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use Hyde\Framework\Concerns\HasTableOfContents;
66
use Hyde\Framework\Contracts\AbstractMarkdownPage;
7-
use Hyde\Framework\Hyde;
7+
use Hyde\Framework\Contracts\RouteContract;
88
use Hyde\Framework\Models\Parsers\DocumentationPageParser;
9+
use Hyde\Framework\Models\Route;
910

1011
class DocumentationPage extends AbstractMarkdownPage
1112
{
@@ -31,27 +32,8 @@ public function getOnlineSourcePath(): string|false
3132
return trim(config('docs.source_file_location_base'), '/').'/'.$this->slug.'.md';
3233
}
3334

34-
/**
35-
* Get the path to the frontpage for the documentation.
36-
*
37-
* It is highly recommended to have an index.md file in the _docs directory,
38-
* however, this method will fall back to a readme.
39-
*
40-
* @since 0.46.x (moved from Hyde::docsIndexPath).
41-
* @deprecated 0.52.x (use the route instead)
42-
*
43-
* @return string|false returns false if no suitable frontpage is found
44-
*/
45-
public static function indexPath(): string|false
35+
public static function home(): ?RouteContract
4636
{
47-
if (file_exists(Hyde::path(static::getSourceDirectory().'/index.md'))) {
48-
return trim(Hyde::pageLink(static::getOutputDirectory().'/index.html'), '/');
49-
}
50-
51-
if (file_exists(Hyde::path(static::getSourceDirectory().'/readme.md'))) {
52-
return trim(Hyde::pageLink(static::getOutputDirectory().'/readme.html'), '/');
53-
}
54-
55-
return false;
37+
return Route::exists('docs/index') ? Route::get('docs/index') : null;
5638
}
5739
}

tests/Unit/DocumentationPageIndexPathTest.php

-76
This file was deleted.

tests/Unit/DocumentationPageTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace Hyde\Framework\Testing\Unit;
44

5+
use Hyde\Framework\Hyde;
56
use Hyde\Framework\HydeServiceProvider;
67
use Hyde\Framework\Models\Pages\DocumentationPage;
8+
use Hyde\Framework\Models\Route;
79
use Hyde\Testing\TestCase;
810

911
/**
@@ -79,4 +81,17 @@ public function test_can_get_documentation_output_path_with_trailing_slashes()
7981
$this->assertEquals('foo', DocumentationPage::getOutputDirectory());
8082
}
8183
}
84+
85+
public function test_home_method_returns_null_when_there_is_no_index_page()
86+
{
87+
$this->assertNull(DocumentationPage::home());
88+
}
89+
90+
public function test_home_method_returns_docs_index_route_when_it_exists()
91+
{
92+
Hyde::touch('_docs/index.md');
93+
$this->assertInstanceOf(Route::class, DocumentationPage::home());
94+
$this->assertEquals(Route::get('docs/index'), DocumentationPage::home());
95+
Hyde::unlink('_docs/index.md');
96+
}
8297
}

0 commit comments

Comments
 (0)