From ea20e0285b6f6ca48150adac3c3c5f0f864778fe Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 15 Dec 2023 15:50:21 +0100 Subject: [PATCH] Add improved conditional to fix override priority 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. But it's just a small thing in an auxiliary command so I think it's fine. --- .../Features/Documentation/DocumentationSearchPage.php | 9 ++++++++- .../tests/Feature/Commands/BuildSearchCommandTest.php | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php index a27408c92fd..a352a250358 100644 --- a/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php +++ b/packages/framework/src/Framework/Features/Documentation/DocumentationSearchPage.php @@ -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; @@ -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 diff --git a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php index faa5f89b75a..dfcf392d5bf 100644 --- a/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php +++ b/packages/framework/tests/Feature/Commands/BuildSearchCommandTest.php @@ -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'); } }