Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issues in the documentation search.json and search.html when using custom output directories #420

Merged
merged 3 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
}
}