Skip to content

Commit

Permalink
Add improved conditional to fix override priority
Browse files Browse the repository at this point in the history
As part of the v2 refactors, since routes aren't discovered yet, we need to check the pages directly.

This also means that custom search pages are now not built by the build:search command. We could change it so that it is, but we don't know if the custom page is a custom search feature, or a page that documents a search feature. So we don't know if this is what the user would want/expect.

Additionally, the kernel API changes to needing to put the overrides in the pages collection instead of the route collection. This is also a very very minor implementation change with minimal impact.
  • Loading branch information
caendesilva committed Dec 16, 2023
1 parent 0838ab4 commit 82dc71f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Hyde\Hyde;
use Hyde\Pages\InMemoryPage;
use Hyde\Pages\DocumentationPage;
use Hyde\Pages\Concerns\HydePage;
use Hyde\Framework\Actions\StaticPageBuilder;
use Hyde\Facades\Config;

Expand Down Expand Up @@ -43,7 +44,13 @@ public function __construct()

public static function enabled(): bool
{
return Config::getBool('docs.create_search_page', true) && ! Hyde::routes()->has(self::routeKey());
return Config::getBool('docs.create_search_page', true) && ! static::anotherSearchPageExists();
}

protected static function anotherSearchPageExists(): bool
{
// Since routes aren't discovered yet, we need to check the pages directly
return Hyde::pages()->first(fn (HydePage $file): bool => $file->getRouteKey() === static::routeKey()) !== null;
}

protected static function routeKey(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public function test_command_uses_search_pages_from_kernel_when_present()
$this->artisan('build:search')->assertExitCode(0);

$this->assertFileExists(Hyde::path('_site/docs/search.json'));
$this->assertFileExists(Hyde::path('_site/docs/search.html'));
// $this->assertFileExists(Hyde::path('_site/docs/search.html'));

$this->assertSame('{"foo":"bar"}', Filesystem::getContents('_site/docs/search.json'));
$this->assertSame('Foo', Filesystem::getContents('_site/docs/search.html'));
// $this->assertSame('Foo', Filesystem::getContents('_site/docs/search.html'));

Filesystem::unlink('_site/docs/search.json');
Filesystem::unlink('_site/docs/search.html');
// Filesystem::unlink('_site/docs/search.html');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ public function testEnabledIsFalseWhenDisabled()

public function testEnabledIsFalseWhenRouteExists()
{
Hyde::routes()->put('docs/search', new InMemoryPage('docs/search'));
Hyde::pages()->put('docs/search', new InMemoryPage('docs/search'));
$this->assertFalse(DocumentationSearchPage::enabled());
}

public function testEnabledIsFalseWhenDisabledAndRouteExists()
{
config(['docs.create_search_page' => false]);
Hyde::routes()->put('docs/search', new InMemoryPage('docs/search'));
Hyde::pages()->put('docs/search', new InMemoryPage('docs/search'));
$this->assertFalse(DocumentationSearchPage::enabled());
}
}

0 comments on commit 82dc71f

Please sign in to comment.