diff --git a/.idea/develop.iml b/.idea/develop.iml index d84546941e4..9b96c033022 100644 --- a/.idea/develop.iml +++ b/.idea/develop.iml @@ -14,6 +14,7 @@ + diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f005094547..5e7bff46f72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,10 +22,13 @@ This serves two purposes: 2. At release time, you can move the Unreleased section changes into a new release version section. ### Added -- for new features. +- Added a `@section` hook to the docs layout to allow yielding content +- HydeRC: Add ping route to check if a HydeRC server is running https://github.com/hydephp/realtime-compiler/issues/9 +- internal: Added an HtmlResponse object to the realtime compiler ### Changed - Change the the Prettier integration to only modify HTML files https://github.com/hydephp/develop/issues/102 +- Change how the `docs/search.html` page is rendered, by handling page logic in the view, to decouple it from the build search command ### Deprecated - for soon-to-be removed features. @@ -34,7 +37,8 @@ This serves two purposes: - for now removed features. ### Fixed -- for any bug fixes. +- HydeRC: Rewrite request docs to docs/index to fix https://github.com/hydephp/realtime-compiler/issues/10 +- Fix bug https://github.com/hydephp/develop/issues/93 where styles were missing on search.html when changing the output directory ro root ### Security - in case of vulnerabilities. diff --git a/packages/framework/resources/views/layouts/docs.blade.php b/packages/framework/resources/views/layouts/docs.blade.php index 7a91c721859..c36f3d6c782 100644 --- a/packages/framework/resources/views/layouts/docs.blade.php +++ b/packages/framework/resources/views/layouts/docs.blade.php @@ -67,6 +67,9 @@ @endphp
$document->hasTorchlight()])> + + @yield('content') +
{!! $document->renderHeader() !!}
diff --git a/packages/framework/resources/views/pages/documentation-search.blade.php b/packages/framework/resources/views/pages/documentation-search.blade.php index a6b6ca5ca4b..a935e2f4914 100644 --- a/packages/framework/resources/views/pages/documentation-search.blade.php +++ b/packages/framework/resources/views/pages/documentation-search.blade.php @@ -1,3 +1,13 @@ -

Search the documentation site

- -@include('hyde::components.docs.search-input') \ No newline at end of file +@php + $page = new \Hyde\Framework\Models\DocumentationPage([], '', 'Search', 'search'); + $title = 'Search'; + $currentPage = $page->getCurrentPagePath(); + $markdown = ''; +@endphp + +@extends('hyde::layouts.docs') +@section('content') +

Search the documentation site

+ + @include('hyde::components.docs.search-input') +@endsection \ No newline at end of file diff --git a/packages/framework/src/Commands/HydeBuildSearchCommand.php b/packages/framework/src/Commands/HydeBuildSearchCommand.php index 1dbd828a7fa..444cf7e8818 100644 --- a/packages/framework/src/Commands/HydeBuildSearchCommand.php +++ b/packages/framework/src/Commands/HydeBuildSearchCommand.php @@ -4,7 +4,6 @@ use Hyde\Framework\Actions\GeneratesDocumentationSearchIndexFile; use Hyde\Framework\Hyde; -use Hyde\Framework\Models\DocumentationPage; use Hyde\Framework\Services\CollectionService; use LaravelZero\Framework\Commands\Command; @@ -61,12 +60,7 @@ protected function createSearchPage(): void $this->comment('Generating search page...'); file_put_contents( Hyde::path('_site/'.config('docs.output_directory', 'docs').'/search.html'), - view('hyde::layouts.docs')->with([ - 'page' => new DocumentationPage([], '', 'Search', 'search'), - 'title' => 'Search', - 'markdown' => view('hyde::pages.documentation-search')->render(), - 'currentPage' => ''.config('docs.output_directory', 'docs').'/search', - ])->render() + view('hyde::pages.documentation-search')->render() ); $this->line(' > Created _site/'.config('docs.output_directory', 'docs').'/search.html in '. diff --git a/packages/realtime-compiler/src/Actions/RendersSearchPage.php b/packages/realtime-compiler/src/Actions/RendersSearchPage.php new file mode 100644 index 00000000000..f783d03dc96 --- /dev/null +++ b/packages/realtime-compiler/src/Actions/RendersSearchPage.php @@ -0,0 +1,19 @@ +bootApplication(); + + return Blade::render(file_get_contents(Hyde::vendorPath('resources/views/pages/documentation-search.blade.php'))); + } +} diff --git a/packages/realtime-compiler/src/Http/HtmlResponse.php b/packages/realtime-compiler/src/Http/HtmlResponse.php new file mode 100644 index 00000000000..d168df78588 --- /dev/null +++ b/packages/realtime-compiler/src/Http/HtmlResponse.php @@ -0,0 +1,16 @@ +withHeaders([ + 'Content-Type' => 'text/html', + 'Content-Length' => strlen($this->responseData['body']), + ]); + + parent::send(); + } +} diff --git a/packages/realtime-compiler/src/Routing/Router.php b/packages/realtime-compiler/src/Routing/Router.php index 1d31e1f947a..873645374a0 100644 --- a/packages/realtime-compiler/src/Routing/Router.php +++ b/packages/realtime-compiler/src/Routing/Router.php @@ -2,10 +2,13 @@ namespace Hyde\RealtimeCompiler\Routing; +use Desilva\Microserve\JsonResponse; use Desilva\Microserve\Request; use Desilva\Microserve\Response; use Hyde\RealtimeCompiler\Actions\AssetFileLocator; +use Hyde\RealtimeCompiler\Actions\RendersSearchPage; use Hyde\RealtimeCompiler\Concerns\SendsErrorResponses; +use Hyde\RealtimeCompiler\Http\HtmlResponse; use Hyde\RealtimeCompiler\Models\FileObject; class Router @@ -25,6 +28,24 @@ public function handle(): Response return $this->proxyStatic(); } + if ($this->shouldRenderSpecial($this->request)) { + if ($this->request->path === '/docs') { + $this->request->path = '/docs/index'; + } + + if ($this->request->path === '/docs/search') { + return new HtmlResponse(200, 'OK', [ + 'body' => (new RendersSearchPage())->__invoke(), + ]); + } + + if ($this->request->path === '/ping') { + return new JsonResponse(200, 'OK', [ + 'server' => 'Hyde/RealtimeCompiler', + ]); + } + } + return PageRouter::handle($this->request); } @@ -72,4 +93,18 @@ protected function proxyStatic(): Response 'Content-Length' => $file->getContentLength(), ]); } + + /** + * If the request is for a special page, we handle it here. + */ + protected function shouldRenderSpecial(Request $request): bool + { + $routes = [ + '/ping', + '/docs', + '/docs/search', + ]; + + return in_array($request->path, $routes); + } }