Skip to content

Commit

Permalink
Update realtime compiler to create missing search index automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Oct 28, 2023
1 parent a42101d commit 65ed297
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/realtime-compiler/src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
use Hyde\RealtimeCompiler\Actions\AssetFileLocator;
use Hyde\RealtimeCompiler\Concerns\SendsErrorResponses;
use Hyde\RealtimeCompiler\Models\FileObject;
use Hyde\RealtimeCompiler\Concerns\InteractsWithLaravel;
use Hyde\Framework\Actions\GeneratesDocumentationSearchIndex;

class Router
{
use SendsErrorResponses;
use InteractsWithLaravel;

protected Request $request;

Expand Down Expand Up @@ -74,7 +77,11 @@ protected function proxyStatic(): Response
$path = AssetFileLocator::find($this->request->path);

if ($path === null) {
return $this->notFound();
if ($this->request->path === '/docs/search.json') {
$path = $this->generateSearchIndex();
} else {
return $this->notFound();
}
}

$file = new FileObject($path);
Expand All @@ -86,4 +93,18 @@ protected function proxyStatic(): Response
'Content-Length' => $file->getContentLength(),
]);
}

/**
* Generate and serve the documentation search index.
*
* Note that this only gets called if the index is not
* yet generated. It does not keep track of if the
* index is up-to-date or not.
*/
protected function generateSearchIndex(): string
{
$this->bootApplication();

return GeneratesDocumentationSearchIndex::handle();
}
}

0 comments on commit 65ed297

Please sign in to comment.