Skip to content

Commit

Permalink
Update core extension to add search index as an in memory page
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 13, 2023
1 parent 9bee9cd commit 4b0a355
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/framework/src/Foundation/HydeCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
use Hyde\Pages\BladePage;
use Hyde\Pages\MarkdownPage;
use Hyde\Pages\MarkdownPost;
use Hyde\Pages\InMemoryPage;
use Hyde\Pages\DocumentationPage;
use Hyde\Foundation\Kernel\PageCollection;
use Hyde\Foundation\Concerns\HydeExtension;
use Hyde\Facades\Features;

use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex;
use function array_filter;
use function array_keys;

Expand All @@ -28,4 +31,18 @@ public static function getPageClasses(): array
DocumentationPage::class => Features::hasDocumentationPages(),
], fn (bool $value): bool => $value));
}

public function discoverPages(PageCollection $collection): void
{
if (Features::hasDocumentationSearch()) {
$collection->addPage(tap(new InMemoryPage('search.json'), function (InMemoryPage $page): void {
$page->macro('compile', function (): string {
return GeneratesDocumentationSearchIndex::generate();
});
$page->macro('getOutputPath', function (): string {
return DocumentationPage::outputDirectory().'/search.json';
});
}));
}
}
}

0 comments on commit 4b0a355

Please sign in to comment.