Skip to content

Commit

Permalink
Merge pull request #420 from hydephp/search-index-bugfixes
Browse files Browse the repository at this point in the history
Fixes issues in the documentation `search.json` and `search.html` when using custom output directories
  • Loading branch information
caendesilva authored Aug 12, 2022
2 parents 379c37b + e5a6371 commit fabe182
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ This release continues refactoring the internal codebase. As part of this, a lar

### Fixed
- MarkdownFileParser not using the Hyde path [#399](https://github.com/hydephp/develop/issues/399)
- Fixes issues in the documentation `search.json` and `search.html` when using custom output directories

### Security
- in case of vulnerabilities.
Expand Down
11 changes: 7 additions & 4 deletions packages/framework/src/Commands/HydeBuildSearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

use Hyde\Framework\Actions\GeneratesDocumentationSearchIndexFile;
use Hyde\Framework\Concerns\ActionCommand;
use Hyde\Framework\Concerns\InteractsWithDirectories;
use Hyde\Framework\Hyde;
use Hyde\Framework\Models\Pages\DocumentationPage;
use Hyde\Framework\Services\DiscoveryService;

/**
Expand All @@ -16,6 +18,8 @@
*/
class HydeBuildSearchCommand extends ActionCommand
{
use InteractsWithDirectories;

/**
* The signature of the command.
*
Expand Down Expand Up @@ -48,11 +52,10 @@ public function handle(): int

if (config('docs.create_search_page', true)) {
$this->action('Generating search page', function () {
$outputDirectory = Hyde::pathToRelative(Hyde::getSiteOutputPath(DocumentationPage::getOutputDirectory()));
$this->needsDirectory(Hyde::path($outputDirectory));
file_put_contents(
Hyde::path(sprintf(
'_site/%s/search.html',
config('docs.output_directory', 'docs')
)),
Hyde::path($outputDirectory.'/search.html'),
view('hyde::pages.documentation-search')->render()
);
}, sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Hyde\Framework\Commands\HydeBuildSearchCommand;
use Hyde\Framework\Hyde;
use Hyde\Framework\Models\Pages\DocumentationPage;
use Hyde\Framework\StaticPageBuilder;
use Hyde\Testing\TestCase;

/**
Expand Down Expand Up @@ -75,4 +77,62 @@ public function test_it_displays_the_estimation_message_when_it_is_greater_than_
->assertExitCode(0);
unlink(Hyde::path('_docs/foo.md'));
}

public function test_search_files_can_be_generated_for_custom_docs_output_directory()
{
DocumentationPage::$outputDirectory = 'foo';
$this->artisan('build:search')
->expectsOutput('Generating documentation site search index...')
->assertExitCode(0);
$this->assertFileExists(Hyde::path('_site/foo/search.json'));
$this->assertFileExists(Hyde::path('_site/foo/search.html'));
unlink(Hyde::path('_site/foo/search.json'));
unlink(Hyde::path('_site/foo/search.html'));
rmdir(Hyde::path('_site/foo'));
}

public function test_search_files_can_be_generated_for_custom_site_output_directory()
{
StaticPageBuilder::$outputPath = Hyde::path('foo');
$this->artisan('build:search')
->expectsOutput('Generating documentation site search index...')
->assertExitCode(0);
$this->assertFileExists(Hyde::path('foo/docs/search.json'));
$this->assertFileExists(Hyde::path('foo/docs/search.html'));
unlink(Hyde::path('foo/docs/search.json'));
unlink(Hyde::path('foo/docs/search.html'));
rmdir(Hyde::path('foo/docs'));
rmdir(Hyde::path('foo'));
}

public function test_search_files_can_be_generated_for_custom_site_and_docs_output_directories()
{
DocumentationPage::$outputDirectory = 'foo';
StaticPageBuilder::$outputPath = Hyde::path('bar');
$this->artisan('build:search')
->expectsOutput('Generating documentation site search index...')
->assertExitCode(0);
$this->assertFileExists(Hyde::path('bar/foo/search.json'));
$this->assertFileExists(Hyde::path('bar/foo/search.html'));
unlink(Hyde::path('bar/foo/search.json'));
unlink(Hyde::path('bar/foo/search.html'));
rmdir(Hyde::path('bar/foo'));
rmdir(Hyde::path('bar'));
}

public function test_search_files_can_be_generated_for_custom_site_and_nested_docs_output_directories()
{
DocumentationPage::$outputDirectory = 'foo';
StaticPageBuilder::$outputPath = Hyde::path('bar/baz');
$this->artisan('build:search')
->expectsOutput('Generating documentation site search index...')
->assertExitCode(0);
$this->assertFileExists(Hyde::path('bar/baz/foo/search.json'));
$this->assertFileExists(Hyde::path('bar/baz/foo/search.html'));
unlink(Hyde::path('bar/baz/foo/search.json'));
unlink(Hyde::path('bar/baz/foo/search.html'));
rmdir(Hyde::path('bar/baz/foo'));
rmdir(Hyde::path('bar/baz'));
rmdir(Hyde::path('bar'));
}
}

0 comments on commit fabe182

Please sign in to comment.