Skip to content

Commit

Permalink
Merge pull request #96 from hydephp/94-bug-hydedocsindexpath-checks-t…
Browse files Browse the repository at this point in the history
…he-hard-coded-source-directory

Fix bug #94: Hyde::docsIndexPath() checks the hard-coded source directory
  • Loading branch information
caendesilva authored Jun 23, 2022
2 parents 99ad45f + b5be479 commit 2d12591
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 2d12591

Please sign in to comment.