Skip to content

Commit 4b62ebb

Browse files
authored
Merge pull request #1123 from hydephp/refactor-formatLink-helper
Update Hyde::formatLink helper to trim all index.html suffixes when using pretty URLs
2 parents 19a7865 + 92296cc commit 4b62ebb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/framework/src/Foundation/Kernel/Hyperlinks.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Hyde\Foundation\HydeKernel;
88
use Hyde\Framework\Exceptions\BaseUrlNotSetException;
99
use Hyde\Framework\Exceptions\FileNotFoundException;
10-
use Hyde\Pages\DocumentationPage;
1110
use Illuminate\Support\Str;
1211

1312
/**
@@ -39,8 +38,8 @@ public function formatLink(string $destination): string
3938
return '/';
4039
}
4140

42-
if ($destination === DocumentationPage::outputDirectory().'/index.html') {
43-
return DocumentationPage::outputDirectory().'/';
41+
if (str_ends_with($destination, 'index.html')) {
42+
return substr($destination, 0, -10);
4443
}
4544

4645
return substr($destination, 0, -5);

packages/framework/tests/Unit/Foundation/HyperlinkFormatHtmlPathTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,16 @@ public function test_helper_does_not_rewrite_documentation_page_index_when_not_u
9898
self::mockConfig(['hyde.pretty_urls' => false]);
9999
$this->assertEquals('docs/index.html', Hyde::formatLink('docs/index.html'));
100100
}
101+
102+
public function test_helpers_rewrites_arbitrary_nested_index_pages_when_using_pretty_urls()
103+
{
104+
self::mockConfig(['hyde.pretty_urls' => true]);
105+
$this->assertEquals('foo/bar/', Hyde::formatLink('foo/bar/index.html'));
106+
}
107+
108+
public function test_helpers_does_not_rewrite_arbitrary_nested_index_pages_when_not_using_pretty_urls()
109+
{
110+
self::mockConfig(['hyde.pretty_urls' => false]);
111+
$this->assertEquals('foo/bar/index.html', Hyde::formatLink('foo/bar/index.html'));
112+
}
101113
}

0 commit comments

Comments
 (0)