Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge development branch into master #104

Merged
merged 13 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/develop.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions packages/framework/resources/views/layouts/docs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
@endphp
<article id="document" itemscope itemtype="http://schema.org/Article" @class(['mx-auto lg:ml-8 prose dark:prose-invert
max-w-3xl', 'torchlight-enabled'=> $document->hasTorchlight()])>

@yield('content')

<header id="document-header">
{!! $document->renderHeader() !!}
</header>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<h1>Search the documentation site</h1>
<style>#searchMenuButton{display:none!important;}#search-results{max-height:unset!important;}</style>
@include('hyde::components.docs.search-input')
@php
$page = new \Hyde\Framework\Models\DocumentationPage([], '', 'Search', 'search');
$title = 'Search';
$currentPage = $page->getCurrentPagePath();
$markdown = '';
@endphp

@extends('hyde::layouts.docs')
@section('content')
<h1>Search the documentation site</h1>
<style>#searchMenuButton{display:none!important;}#search-results{max-height:unset!important;}</style>
@include('hyde::components.docs.search-input')
@endsection
8 changes: 1 addition & 7 deletions packages/framework/src/Commands/HydeBuildSearchCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 <info>_site/'.config('docs.output_directory', 'docs').'/search.html</> in '.
Expand Down
19 changes: 19 additions & 0 deletions packages/realtime-compiler/src/Actions/RendersSearchPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Hyde\RealtimeCompiler\Actions;

use Hyde\Framework\Hyde;
use Hyde\RealtimeCompiler\Concerns\InteractsWithLaravel;
use Illuminate\Support\Facades\Blade;

class RendersSearchPage
{
use InteractsWithLaravel;

public function __invoke()
{
$this->bootApplication();

return Blade::render(file_get_contents(Hyde::vendorPath('resources/views/pages/documentation-search.blade.php')));
}
}
16 changes: 16 additions & 0 deletions packages/realtime-compiler/src/Http/HtmlResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Hyde\RealtimeCompiler\Http;

class HtmlResponse extends \Desilva\Microserve\Response
{
public function send(): void
{
$this->withHeaders([
'Content-Type' => 'text/html',
'Content-Length' => strlen($this->responseData['body']),
]);

parent::send();
}
}
35 changes: 35 additions & 0 deletions packages/realtime-compiler/src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}
}