Skip to content

Commit

Permalink
Support getting the search page from the kernel
Browse files Browse the repository at this point in the history
In case it's been modified or injected somehow, this is a nicety to have
  • Loading branch information
caendesilva committed Dec 14, 2023
1 parent 158c6f2 commit 873b928
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/framework/src/Console/Commands/BuildSearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

namespace Hyde\Console\Commands;

use LaravelZero\Framework\Commands\Command;
use Hyde\Pages\Concerns\HydePage;
use Hyde\Foundation\Facades\Pages;
use Hyde\Framework\Actions\StaticPageBuilder;
use Hyde\Framework\Exceptions\FileNotFoundException;
use LaravelZero\Framework\Commands\Command;
use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex;
use Hyde\Framework\Features\Documentation\DocumentationSearchPage;

Expand All @@ -22,12 +25,21 @@ class BuildSearchCommand extends Command

public function handle(): int
{
StaticPageBuilder::handle(GeneratesDocumentationSearchIndex::makePage());
StaticPageBuilder::handle($this->getPageFromKernel() ?? GeneratesDocumentationSearchIndex::makePage());

This comment has been minimized.

Copy link
@caendesilva

caendesilva Dec 14, 2023

Author Member

OTOH not sure if this is how we would want to support the search index being changed

This comment has been minimized.

Copy link
@caendesilva

caendesilva Dec 14, 2023

Author Member

Nvm, this is so that we use the model initialized by the core extension whenever possible


if (DocumentationSearchPage::enabled()) {
DocumentationSearchPage::generate();
}

return Command::SUCCESS;
}

protected function getPageFromKernel(): ?HydePage
{
try {
return Pages::getPage('search.json');
} catch (FileNotFoundException) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

use Hyde\Facades\Filesystem;
use Hyde\Hyde;
use Hyde\Pages\InMemoryPage;
use Hyde\Pages\DocumentationPage;
use Hyde\Testing\TestCase;
use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex;

/**
* @covers \Hyde\Console\Commands\BuildSearchCommand
Expand Down Expand Up @@ -103,4 +105,18 @@ public function test_search_files_can_be_generated_for_custom_site_and_nested_do

Filesystem::deleteDirectory('foo');
}

public function test_command_uses_page_from_kernel_when_present()
{
Hyde::pages()->addPage(tap(GeneratesDocumentationSearchIndex::makePage(), function (InMemoryPage $page): void {
$page->macro('compile', fn () => '{"foo":"bar"}');
}));

$this->artisan('build:search')->assertExitCode(0);
$this->assertFileExists(Hyde::path('_site/docs/search.json'));
$this->assertSame('{"foo":"bar"}', Filesystem::getContents('_site/docs/search.json'));

Filesystem::unlink('_site/docs/search.json');
Filesystem::unlink('_site/docs/search.html');
}
}

0 comments on commit 873b928

Please sign in to comment.