Skip to content

Commit

Permalink
Merge pull request #1123 from hydephp/refactor-formatLink-helper
Browse files Browse the repository at this point in the history
Update Hyde::formatLink helper to trim all index.html suffixes when using pretty URLs
  • Loading branch information
caendesilva authored Feb 26, 2023
2 parents 19a7865 + 92296cc commit 4b62ebb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/framework/src/Foundation/Kernel/Hyperlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Hyde\Foundation\HydeKernel;
use Hyde\Framework\Exceptions\BaseUrlNotSetException;
use Hyde\Framework\Exceptions\FileNotFoundException;
use Hyde\Pages\DocumentationPage;
use Illuminate\Support\Str;

/**
Expand Down Expand Up @@ -39,8 +38,8 @@ public function formatLink(string $destination): string
return '/';
}

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

return substr($destination, 0, -5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,16 @@ public function test_helper_does_not_rewrite_documentation_page_index_when_not_u
self::mockConfig(['hyde.pretty_urls' => false]);
$this->assertEquals('docs/index.html', Hyde::formatLink('docs/index.html'));
}

public function test_helpers_rewrites_arbitrary_nested_index_pages_when_using_pretty_urls()
{
self::mockConfig(['hyde.pretty_urls' => true]);
$this->assertEquals('foo/bar/', Hyde::formatLink('foo/bar/index.html'));
}

public function test_helpers_does_not_rewrite_arbitrary_nested_index_pages_when_not_using_pretty_urls()
{
self::mockConfig(['hyde.pretty_urls' => false]);
$this->assertEquals('foo/bar/index.html', Hyde::formatLink('foo/bar/index.html'));
}
}

0 comments on commit 4b62ebb

Please sign in to comment.