Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug #94: Hyde::docsIndexPath() checks the hard-coded source directory #96

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/framework/src/Concerns/Internal/FileHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Hyde\Framework\Concerns\Internal;

use Hyde\Framework\Models\DocumentationPage;

/**
* Offloads file helper methods for the Hyde Facade.
*
Expand Down Expand Up @@ -31,11 +33,11 @@ public static function getDocumentationOutputDirectory(): string
*/
public static function docsIndexPath(): string|false
{
if (file_exists(static::path('_docs/index.md'))) {
if (file_exists(static::path(DocumentationPage::$sourceDirectory.'/index.md'))) {
return trim(static::pageLink(static::getDocumentationOutputDirectory().'/index.html'), '/');
}

if (file_exists(static::path('_docs/readme.md'))) {
if (file_exists(static::path(DocumentationPage::$sourceDirectory.'/readme.md'))) {
return trim(static::pageLink(static::getDocumentationOutputDirectory().'/readme.html'), '/');
}

Expand Down
13 changes: 13 additions & 0 deletions packages/framework/tests/Feature/HydeDocsIndexPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Hyde\Framework\Testing\Feature;

use Hyde\Framework\Hyde;
use Hyde\Framework\Models\DocumentationPage;
use Hyde\Testing\TestCase;

class HydeDocsIndexPathTest extends TestCase
Expand Down Expand Up @@ -45,6 +46,18 @@ public function test_returns_index_if_only_index_exist()
$this->assertEquals('docs/index.html', Hyde::docsIndexPath());
}

public function test_helper_can_find_index_path_when_custom_docs_directory_is_used()
{
mkdir(Hyde::path('foo'));
file_put_contents(Hyde::path('foo/index.md'), '');

DocumentationPage::$sourceDirectory = 'foo';
$this->assertEquals('docs/index.html', Hyde::docsIndexPath());

unlink(Hyde::path('foo/index.md'));
rmdir(Hyde::path('foo'));
}

private function setReadme()
{
file_put_contents(Hyde::path('_docs/readme.md'), '');
Expand Down