Skip to content

Commit

Permalink
Rewrite index.html to /, fixing half of #353
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed May 15, 2022
1 parent ee2841d commit 740bcf1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Concerns/Internal/FileHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public static function pageLink(string $destination): string
{
if (config('hyde.prettyUrls', false) === true) {
if (str_ends_with($destination, '.html')) {
if ($destination === 'index.html') {
return '/';
}
return substr($destination, 0, -5);
}
}
Expand All @@ -105,7 +108,7 @@ public static function relativeLink(string $destination, string $current = ''):
}
$route .= static::pageLink($destination);

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

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/FileHelperPageLinkPrettyUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ public function test_helper_respects_absolute_urls_with_pretty_urls_enabled()
config(['hyde.prettyUrls' => true]);
$this->assertEquals('/foo/bar.jpg', Hyde::pageLink('/foo/bar.jpg'));
}

public function test_helper_rewrites_index_when_using_pretty_urls()
{
config(['hyde.prettyUrls' => true]);
$this->assertEquals('/', Hyde::pageLink('index.html'));
}
}
8 changes: 8 additions & 0 deletions tests/Unit/FileHelperRelativeLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,12 @@ public function test_helper_returns_does_not_return_pretty_url_if_when_enabled_b
config(['hyde.prettyUrls' => true]);
$this->assertEquals('../foo.png', Hyde::relativeLink('foo.png', 'foo/bar.html'));
}

public function test_helper_rewrites_index_when_using_pretty_urls()
{
config(['hyde.prettyUrls' => true]);
$this->assertEquals('/', Hyde::relativeLink('index.html', 'foo.html'));
$this->assertEquals('../', Hyde::relativeLink('index.html', 'foo/bar.html'));
$this->assertEquals('../../', Hyde::relativeLink('index.html', 'foo/bar/baz.html'));
}
}

0 comments on commit 740bcf1

Please sign in to comment.