From 65ed297c0f8c8530c86b89912d864ef4e20672b9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 15:50:34 +0200 Subject: [PATCH 1/4] Update realtime compiler to create missing search index automatically --- .../realtime-compiler/src/Routing/Router.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/realtime-compiler/src/Routing/Router.php b/packages/realtime-compiler/src/Routing/Router.php index 49aa7169d15..0dd9be9e97a 100644 --- a/packages/realtime-compiler/src/Routing/Router.php +++ b/packages/realtime-compiler/src/Routing/Router.php @@ -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; @@ -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); @@ -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(); + } } From d79a0a37af0c8f22e17a7b099a33e183d8555c31 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 15:58:09 +0200 Subject: [PATCH 2/4] Generate the search index each time it's requested --- .../realtime-compiler/src/Routing/Router.php | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/realtime-compiler/src/Routing/Router.php b/packages/realtime-compiler/src/Routing/Router.php index 0dd9be9e97a..9b3ca859784 100644 --- a/packages/realtime-compiler/src/Routing/Router.php +++ b/packages/realtime-compiler/src/Routing/Router.php @@ -74,14 +74,14 @@ 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) { - if ($this->request->path === '/docs/search.json') { - $path = $this->generateSearchIndex(); - } else { - return $this->notFound(); - } + return $this->notFound(); } $file = new FileObject($path); @@ -95,16 +95,12 @@ protected function proxyStatic(): Response } /** - * 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. + * Generate the documentation search index. */ - protected function generateSearchIndex(): string + protected function generateSearchIndex(): void { $this->bootApplication(); - return GeneratesDocumentationSearchIndex::handle(); + GeneratesDocumentationSearchIndex::handle(); } } From ced46b594a16f74dcf21ac3730abd5f68126f5e6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 15:58:28 +0200 Subject: [PATCH 3/4] Update documentation for realtime compiler live search --- docs/creating-content/documentation-pages.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/creating-content/documentation-pages.md b/docs/creating-content/documentation-pages.md index 752498e7ce5..c3694d3350f 100644 --- a/docs/creating-content/documentation-pages.md +++ b/docs/creating-content/documentation-pages.md @@ -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 From 4ba0cfad86e9624c9d1baef36327fb1456836748 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Sat, 28 Oct 2023 16:01:32 +0200 Subject: [PATCH 4/4] Update RELEASE_NOTES.md --- RELEASE_NOTES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 1883d530bf2..8f5df265e4e 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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. @@ -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.