Skip to content

Commit

Permalink
Merge pull request #1405 from hydephp/support-realtime-documentation-…
Browse files Browse the repository at this point in the history
…searches-in-realtime-compiler

Update realtime compiler to generate search indexes on demand
  • Loading branch information
caendesilva authored Oct 28, 2023
2 parents a42101d + 4ba0cfa commit e1535a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This serves two purposes:
### Changed
- Realtime Compiler: The `DashboardController` class is now marked as internal, as it is not intended to be used outside of the package https://github.com/hydephp/develop/pull/1394
- Updated the realtime compiler server configuration options in https://github.com/hydephp/develop/pull/1395 (backwards compatible)
- Updated the realtime compiler to generate the documentation search index each time it's requested in https://github.com/hydephp/develop/pull/1405 (fixes https://github.com/hydephp/develop/issues/1404)

### Deprecated
- for soon-to-be removed features.
Expand All @@ -31,6 +32,7 @@ This serves two purposes:
- Updated the vendor publish command to support parent Laravel Prompts implementation in https://github.com/hydephp/develop/pull/1388
- Fixed wrong version constant in https://github.com/hydephp/develop/pull/1391
- Fixed improperly formatted exception message in https://github.com/hydephp/develop/pull/1399
- Fixed missing support for missing and out of date search indexes when previewing site https://github.com/hydephp/develop/issues/1404 in https://github.com/hydephp/develop/pull/1405

### Security
- in case of vulnerabilities.
7 changes: 2 additions & 5 deletions docs/creating-content/documentation-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,9 @@ navigation menu items are hidden. The page will still be accessible as normal bu
]
```

### Search with realtime compiler

While the Realtime Compiler (what powers the `php hyde serve` command) serves the search index, however, it does not
compile the index automatically. So if you're missing the search when previewing your site, run either `php hyde build`
or `php hyde build:search` to compile the search index.
### Live search with the realtime compiler

The Realtime Compiler that powers the `php hyde serve` command will automatically generate a fresh search index each time the browser requests it.

## Automatic "Edit Page" button

Expand Down
17 changes: 17 additions & 0 deletions 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 @@ -71,6 +74,10 @@ protected function shouldProxy(Request $request): bool
*/
protected function proxyStatic(): Response
{
if ($this->request->path === '/docs/search.json') {
$this->generateSearchIndex();
}

$path = AssetFileLocator::find($this->request->path);

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

/**
* Generate the documentation search index.
*/
protected function generateSearchIndex(): void
{
$this->bootApplication();

GeneratesDocumentationSearchIndex::handle();
}
}

0 comments on commit e1535a4

Please sign in to comment.