Skip to content

Commit d15496b

Browse files
authored
Merge pull request #1238 from hydephp/bugfixes
Update pretty relative index links to rewrite to `./` instead of `/`
2 parents 03d3235 + d5f89a2 commit d15496b

File tree

5 files changed

+50
-29
lines changed

5 files changed

+50
-29
lines changed

_pages/404.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Sorry, the page you are looking for could not be found.
3232
</p>
3333

34-
<a href="{{ config('hyde.url') ?? '/' }}">
34+
<a href="{{ config('hyde.url') ?? './' }}">
3535
<button
3636
class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg">
3737
Go Home

packages/framework/resources/views/pages/404.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Sorry, the page you are looking for could not be found.
3232
</p>
3333

34-
<a href="{{ config('hyde.url') ?? '/' }}">
34+
<a href="{{ config('hyde.url') ?? './' }}">
3535
<button
3636
class="bg-transparent text-grey-darkest font-bold uppercase tracking-wide py-3 px-6 border-2 border-grey-light hover:border-grey rounded-lg">
3737
Go Home

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public function relativeLink(string $destination): string
7878
}
7979
$route .= $this->formatLink($destination);
8080

81+
if (Config::getBool('hyde.pretty_urls', false) === true && $route === '/') {
82+
return './';
83+
}
84+
8185
return str_replace('//', '/', $route);
8286
}
8387

packages/framework/tests/Unit/BreadcrumbsComponentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function testCanGenerateBreadcrumbsForIndexPageWithPrettyUrls()
105105
self::mockConfig(['hyde.pretty_urls' => true]);
106106
$this->mockPage(new MarkdownPage('index'));
107107

108-
$this->assertSame(['/' => 'Home'], (new BreadcrumbsComponent())->breadcrumbs);
108+
$this->assertSame(['./' => 'Home'], (new BreadcrumbsComponent())->breadcrumbs);
109109
}
110110

111111
public function testCanGenerateBreadcrumbsForNestedPageWithPrettyUrls()

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

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,99 +5,116 @@
55
namespace Hyde\Framework\Testing\Unit\Foundation;
66

77
use Hyde\Hyde;
8-
use Hyde\Testing\TestCase;
8+
use Hyde\Support\Facades\Render;
9+
use Hyde\Support\Models\RenderData;
10+
use Hyde\Testing\InteractsWithPages;
11+
use Hyde\Testing\UnitTestCase;
12+
use Illuminate\Support\Facades\View;
13+
use Illuminate\View\Factory;
14+
use Mockery;
915

1016
/**
1117
* @covers \Hyde\Foundation\Kernel\Hyperlinks::relativeLink
1218
*/
13-
class HyperlinkFileHelperRelativeLinkTest extends TestCase
19+
class HyperlinkFileHelperRelativeLinkTest extends UnitTestCase
1420
{
15-
public function test_helper_returns_string_as_is_if_current_is_not_set()
21+
use InteractsWithPages;
22+
23+
protected static bool $needsKernel = true;
24+
protected static bool $needsConfig = true;
25+
26+
protected function setUp(): void
27+
{
28+
Render::swap(new RenderData());
29+
View::swap(Mockery::mock(Factory::class)->makePartial());
30+
}
31+
32+
public function testHelperReturnsStringAsIsIfCurrentIsNotSet()
1633
{
1734
$this->assertEquals('foo/bar.html', Hyde::relativeLink('foo/bar.html'));
1835
}
1936

20-
public function test_helper_injects_proper_number_of_doubles_slash()
37+
public function testHelperInjectsProperNumberOfDoublesSlash()
2138
{
2239
$this->mockCurrentPage('foo/bar.html');
2340
$this->assertEquals('../foo.html', Hyde::relativeLink('foo.html'));
2441
}
2542

26-
public function test_helper_injects_proper_number_of_doubles_slash_for_deeply_nested_paths()
43+
public function testHelperInjectsProperNumberOfDoublesSlashForDeeplyNestedPaths()
2744
{
2845
$this->mockCurrentPage('foo/bar/baz/qux.html');
2946
$this->assertEquals('../../../foo.html', Hyde::relativeLink('foo.html'));
3047
}
3148

32-
public function test_helper_handles_destination_without_file_extension()
49+
public function testHelperHandlesDestinationWithoutFileExtension()
3350
{
3451
$this->mockCurrentPage('foo/bar.html');
3552
$this->assertEquals('../foo', Hyde::relativeLink('foo'));
3653
}
3754

38-
public function test_helper_handles_current_without_file_extension()
55+
public function testHelperHandlesCurrentWithoutFileExtension()
3956
{
4057
$this->mockCurrentPage('foo/bar');
4158
$this->assertEquals('../foo.html', Hyde::relativeLink('foo.html'));
4259
}
4360

44-
public function test_helper_handles_case_without_any_file_extensions()
61+
public function testHelperHandlesCaseWithoutAnyFileExtensions()
4562
{
4663
$this->mockCurrentPage('foo/bar');
4764
$this->assertEquals('../foo', Hyde::relativeLink('foo'));
4865
}
4966

50-
public function test_helper_handles_case_with_mixed_file_extensions()
67+
public function testHelperHandlesCaseWithMixedFileExtensions()
5168
{
5269
$this->mockCurrentPage('foo/bar.md');
5370
$this->assertEquals('../foo.md', Hyde::relativeLink('foo.md'));
5471
$this->mockCurrentPage('foo/bar.txt');
5572
$this->assertEquals('../foo.txt', Hyde::relativeLink('foo.txt'));
5673
}
5774

58-
public function test_helper_handles_different_file_extensions()
75+
public function testHelperHandlesDifferentFileExtensions()
5976
{
6077
$this->mockCurrentPage('foo/bar');
6178
$this->assertEquals('../foo.png', Hyde::relativeLink('foo.png'));
6279
$this->assertEquals('../foo.css', Hyde::relativeLink('foo.css'));
6380
$this->assertEquals('../foo.js', Hyde::relativeLink('foo.js'));
6481
}
6582

66-
public function test_helper_returns_pretty_url_if_enabled_and_destination_is_a_html_file()
83+
public function testHelperReturnsPrettyUrlIfEnabledAndDestinationIsAHtmlFile()
6784
{
68-
config(['hyde.pretty_urls' => true]);
85+
self::mockConfig(['hyde.pretty_urls' => true]);
6986
$this->mockCurrentPage('foo/bar.html');
7087
$this->assertEquals('../foo', Hyde::relativeLink('foo.html'));
7188
}
7289

73-
public function test_helper_method_does_not_require_current_path_to_be_html_to_use_pretty_urls()
90+
public function testHelperMethodDoesNotRequireCurrentPathToBeHtmlToUsePrettyUrls()
7491
{
75-
config(['hyde.pretty_urls' => true]);
92+
self::mockConfig(['hyde.pretty_urls' => true]);
7693
$this->mockCurrentPage('foo/bar');
7794
$this->assertEquals('../foo', Hyde::relativeLink('foo.html'));
7895
}
7996

80-
public function test_helper_returns_does_not_return_pretty_url_if_when_enabled_but_and_destination_is_not_a_html_file()
97+
public function testHelperReturnsDoesNotReturnPrettyUrlIfWhenEnabledButAndDestinationIsNotAHtmlFile()
8198
{
82-
config(['hyde.pretty_urls' => true]);
99+
self::mockConfig(['hyde.pretty_urls' => true]);
83100
$this->mockCurrentPage('foo/bar.html');
84101
$this->assertEquals('../foo.png', Hyde::relativeLink('foo.png'));
85102
}
86103

87-
public function test_helper_rewrites_index_when_using_pretty_urls()
104+
public function testHelperRewritesIndexWhenUsingPrettyUrls()
88105
{
89-
config(['hyde.pretty_urls' => true]);
106+
self::mockConfig(['hyde.pretty_urls' => true]);
90107
$this->mockCurrentPage('foo.html');
91-
$this->assertEquals('/', Hyde::relativeLink('index.html'));
108+
$this->assertEquals('./', Hyde::relativeLink('index.html'));
92109
$this->mockCurrentPage('foo/bar.html');
93110
$this->assertEquals('../', Hyde::relativeLink('index.html'));
94111
$this->mockCurrentPage('foo/bar/baz.html');
95112
$this->assertEquals('../../', Hyde::relativeLink('index.html'));
96113
}
97114

98-
public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls()
115+
public function testHelperDoesNotRewriteIndexWhenNotUsingPrettyUrls()
99116
{
100-
config(['hyde.pretty_urls' => false]);
117+
self::mockConfig(['hyde.pretty_urls' => false]);
101118
$this->mockCurrentPage('foo.html');
102119
$this->assertEquals('index.html', Hyde::relativeLink('index.html'));
103120
$this->mockCurrentPage('foo/bar.html');
@@ -106,9 +123,9 @@ public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls()
106123
$this->assertEquals('../../index.html', Hyde::relativeLink('index.html'));
107124
}
108125

109-
public function test_helper_rewrites_documentation_page_index_when_using_pretty_urls()
126+
public function testHelperRewritesDocumentationPageIndexWhenUsingPrettyUrls()
110127
{
111-
config(['hyde.pretty_urls' => true]);
128+
self::mockConfig(['hyde.pretty_urls' => true]);
112129
$this->mockCurrentPage('foo.html');
113130
$this->assertEquals('docs/', Hyde::relativeLink('docs/index.html'));
114131
$this->mockCurrentPage('docs.html');
@@ -119,9 +136,9 @@ public function test_helper_rewrites_documentation_page_index_when_using_pretty_
119136
$this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html'));
120137
}
121138

122-
public function test_helper_does_not_rewrite_documentation_page_index_when_not_using_pretty_urls()
139+
public function testHelperDoesNotRewriteDocumentationPageIndexWhenNotUsingPrettyUrls()
123140
{
124-
config(['hyde.pretty_urls' => false]);
141+
self::mockConfig(['hyde.pretty_urls' => false]);
125142
$this->mockCurrentPage('foo.html');
126143
$this->assertEquals('docs/index.html', Hyde::relativeLink('docs/index.html'));
127144
$this->mockCurrentPage('docs.html');
@@ -132,7 +149,7 @@ public function test_helper_does_not_rewrite_documentation_page_index_when_not_u
132149
$this->assertEquals('../docs/index.html', Hyde::relativeLink('docs/index.html'));
133150
}
134151

135-
public function test_helper_does_not_rewrite_already_processed_links()
152+
public function testHelperDoesNotRewriteAlreadyProcessedLinks()
136153
{
137154
$this->assertEquals('../foo', Hyde::relativeLink('../foo'));
138155
}

0 commit comments

Comments
 (0)