Skip to content

Commit

Permalink
Update pretty relative index links to rewrite to ./ instead of /
Browse files Browse the repository at this point in the history
Update pretty relative index links to rewrite to `./` instead of `/` so they are indeed relative
  • Loading branch information
caendesilva committed Mar 8, 2023
1 parent 2b8c026 commit ce627d0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion _pages/404.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Sorry, the page you are looking for could not be found.
</p>

<a href="{{ config('hyde.url') ?? '/' }}">
<a href="{{ config('hyde.url') ?? './' }}">
<button
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">
Go Home
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/resources/views/pages/404.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
Sorry, the page you are looking for could not be found.
</p>

<a href="{{ config('hyde.url') ?? '/' }}">
<a href="{{ config('hyde.url') ?? './' }}">
<button
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">
Go Home
Expand Down
4 changes: 4 additions & 0 deletions packages/framework/src/Foundation/Kernel/Hyperlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function relativeLink(string $destination): string
}
$route .= $this->formatLink($destination);

if (Config::getBool('hyde.pretty_urls', false) === true && $route === '/') {
return './';
}

return str_replace('//', '/', $route);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/framework/tests/Unit/BreadcrumbsComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testCanGenerateBreadcrumbsForIndexPageWithPrettyUrls()
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockPage(new MarkdownPage('index'));

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

public function testCanGenerateBreadcrumbsForNestedPageWithPrettyUrls()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testHelperRewritesIndexWhenUsingPrettyUrls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
$this->mockCurrentPage('foo.html');
$this->assertEquals('/', Hyde::relativeLink('index.html'));
$this->assertEquals('./', Hyde::relativeLink('index.html'));
$this->mockCurrentPage('foo/bar.html');
$this->assertEquals('../', Hyde::relativeLink('index.html'));
$this->mockCurrentPage('foo/bar/baz.html');
Expand Down

0 comments on commit ce627d0

Please sign in to comment.