Skip to content

Commit 550edf7

Browse files
committed
Rewrite index docs path to pretty url, fix #353
1 parent 3f01ef7 commit 550edf7

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

resources/views/layouts/docs.blade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<nav id="mobile-navigation">
1515
<strong class="mr-auto">
1616
@if(Hyde::docsIndexPath() !== false)
17-
<a href="{{ basename(Hyde::docsIndexPath()) }}">
17+
<a href="{{ Hyde::relativeLink(Hyde::docsIndexPath(), $currentPage) }}">
1818
{{ config('hyde.docsSidebarHeaderTitle', 'Documentation') }}
1919
</a>
2020
@else
@@ -34,7 +34,7 @@
3434
<div id="sidebar-brand">
3535
<strong>
3636
@if(Hyde::docsIndexPath() !== false)
37-
<a href="{{ basename(Hyde::docsIndexPath()) }}">
37+
<a href="{{ Hyde::relativeLink(Hyde::docsIndexPath(), $currentPage) }}">
3838
{{ config('hyde.docsSidebarHeaderTitle', 'Documentation') }}
3939
</a>
4040
@else

src/Concerns/Internal/FileHelpers.php

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public static function pageLink(string $destination): string
8585
if ($destination === 'index.html') {
8686
return '/';
8787
}
88+
if ($destination === static::docsDirectory().'/index.html') {
89+
return static::docsDirectory().'/';
90+
}
8891

8992
return substr($destination, 0, -5);
9093
}

tests/Unit/FileHelperPageLinkPrettyUrlTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,16 @@ public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls()
8080
config(['hyde.prettyUrls' => false]);
8181
$this->assertEquals('index.html', Hyde::pageLink('index.html'));
8282
}
83+
84+
public function test_helper_rewrites_documentation_page_index_when_using_pretty_urls()
85+
{
86+
config(['hyde.prettyUrls' => true]);
87+
$this->assertEquals('docs/', Hyde::pageLink('docs/index.html'));
88+
}
89+
90+
public function test_helper_does_not_rewrite_documentation_page_index_when_not_using_pretty_urls()
91+
{
92+
config(['hyde.prettyUrls' => false]);
93+
$this->assertEquals('docs/index.html', Hyde::pageLink('docs/index.html'));
94+
}
8395
}

tests/Unit/FileHelperRelativeLinkTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,13 @@ public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls()
9999
$this->assertEquals('../index.html', Hyde::relativeLink('index.html', 'foo/bar.html'));
100100
$this->assertEquals('../../index.html', Hyde::relativeLink('index.html', 'foo/bar/baz.html'));
101101
}
102+
103+
public function test_helper_rewrites_documentation_page_index_when_using_pretty_urls()
104+
{
105+
config(['hyde.prettyUrls' => true]);
106+
$this->assertEquals('docs/', Hyde::relativeLink('docs/index.html', 'foo.html'));
107+
$this->assertEquals('docs/', Hyde::relativeLink('docs/index.html', 'docs.html'));
108+
$this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html', 'foo/bar.html'));
109+
$this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html', 'docs/foo.html'));
110+
}
102111
}

0 commit comments

Comments
 (0)