diff --git a/.github/workflows/end-to-end-testing.yml b/.github/workflows/end-to-end-testing.yml index c9642c31c5a..b9dbc344bac 100644 --- a/.github/workflows/end-to-end-testing.yml +++ b/.github/workflows/end-to-end-testing.yml @@ -30,7 +30,7 @@ jobs: run: vendor/bin/pest --stop-on-failure - name: Prepare the Environment - run: echo -e "APP_URL=http://localhost:8080 \nDUSK_ENABLED=true" > .env + run: echo -e "APP_URL=http://localhost:8080 \nDUSK_ENABLED=true\nSERVER_DASHBOARD=false" > .env - name: Upgrade Chrome Driver run: php hyde dusk:chrome-driver `/opt/google/chrome/chrome --version | cut -d " " -f3 | cut -d "." -f1` diff --git a/config/hyde.php b/config/hyde.php index 851d7a0f425..a840b562381 100644 --- a/config/hyde.php +++ b/config/hyde.php @@ -28,6 +28,7 @@ 'server' => [ 'port' => env('SERVER_PORT', 8080), + 'dashboard' => env('SERVER_DASHBOARD', true), ], /* diff --git a/packages/framework/config/hyde.php b/packages/framework/config/hyde.php index 851d7a0f425..a840b562381 100644 --- a/packages/framework/config/hyde.php +++ b/packages/framework/config/hyde.php @@ -28,6 +28,7 @@ 'server' => [ 'port' => env('SERVER_PORT', 8080), + 'dashboard' => env('SERVER_DASHBOARD', true), ], /* diff --git a/packages/realtime-compiler/resources/dashboard.blade.php b/packages/realtime-compiler/resources/dashboard.blade.php new file mode 100644 index 00000000000..fed651f3e40 --- /dev/null +++ b/packages/realtime-compiler/resources/dashboard.blade.php @@ -0,0 +1,111 @@ +@php /** @var \Hyde\RealtimeCompiler\Http\DashboardController $dashboard */ @endphp + + + + + + + {{ $title }} + + + + +
+
+
+

{{ $title }}

+
+

Welcome to the dashboard for your HydePHP site.

+

This page is accessible through the Hyde Realtime Compiler and will not be saved to your static site.

+
+
+
+
+
+
+
+

Project Information

+
+
+ + + @foreach($dashboard->getProjectInformation() as $type => $info) + + @endforeach + +
+ {{ $type }} + {{ $info }} +
+
+
+
+
+
+
+
+
+

Site Pages & Routes

+
+
+ + + @foreach(['Page Type', 'Route Key', 'Source File', 'Output File', 'Identifier'] as $header) + + @endforeach + + + @foreach($dashboard->getPageList() as $route) + + + + + + + + + @endforeach +
{{ $header }}Actions
+ {{ class_basename($route->getPageClass()) }} + + {{ $route->getRouteKey() }} + + {{ $route->getSourcePath() }} + + {{ $route->getOutputPath() }} + + {{ $route->getPageIdentifier() }} + + View +
+
+
+
+
+
+ + + diff --git a/packages/realtime-compiler/src/Http/DashboardController.php b/packages/realtime-compiler/src/Http/DashboardController.php new file mode 100644 index 00000000000..13ac6bd93c0 --- /dev/null +++ b/packages/realtime-compiler/src/Http/DashboardController.php @@ -0,0 +1,169 @@ +title = config('site.name').' - Dashboard'; + } + + public function show(): string + { + return AnonymousViewCompiler::call(__DIR__.'/../../resources/dashboard.blade.php', array_merge( + (array) $this, ['dashboard' => $this, 'request' => Request::capture()], + )); + } + + public function getVersion(): string + { + $version = InstalledVersions::getPrettyVersion('hyde/realtime-compiler'); + + return str_starts_with($version, 'dev-') ? $version : "v$version"; + } + + public function getProjectInformation(): array + { + return [ + 'Git Version:' => app('git.version'), + 'Hyde Version:' => InstalledVersions::getPrettyVersion('hyde/hyde') ?: 'unreleased', + 'Framework Version:' => InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased', + 'Project Path:' => Hyde::path(), + ]; + } + + /** @return array */ + public function getPageList(): array + { + return Hyde::routes()->all(); + } + + public static function enabled(): bool + { + return config('hyde.server.dashboard', true); + } + + // This method is called from the PageRouter and allows us to serve a dynamic welcome page + public static function renderIndexPage(HydePage $page): string + { + $contents = file_get_contents((new StaticPageBuilder($page))->__invoke()); + + // If the page is the default welcome page we inject dashboard components + if (str_contains($contents, 'This is the default homepage')) { + if (config('hyde.server.dashboard.welcome-banner', true)) { + $contents = str_replace("\n ", + sprintf("%s\n\n", self::welcomeComponent()), + $contents); + } + + if (config('hyde.server.dashboard.welcome-dashboard', true)) { + $contents = str_replace('', sprintf("%s\n", self::welcomeFrame()), $contents); + } + + if (config('hyde.server.dashboard.button', false)) { + $contents = self::injectDashboardButton($contents); + } + } + + return $contents; + } + + protected static function injectDashboardButton(string $contents): string + { + return str_replace('', sprintf('%s', self::button()), $contents); + } + + protected static function button(): string + { + return <<<'HTML' + + Dashboard + HTML; + } + + protected static function welcomeComponent(): string + { + $dashboardMessage = config('hyde.server.dashboard.welcome-dashboard', true) + ? '
Scroll down to see it, or visit /dashboard at any time!' : ''; + + return << +
+
+

+ New When using the Realtime Compiler, you now have a content dashboard! + $dashboardMessage +

+ + + + +
+ + HTML; + } + + protected static function welcomeFrame(): string + { + return <<<'HTML' + + HTML; + } +} diff --git a/packages/realtime-compiler/src/Routing/PageRouter.php b/packages/realtime-compiler/src/Routing/PageRouter.php index 9727b624787..3230547b88f 100644 --- a/packages/realtime-compiler/src/Routing/PageRouter.php +++ b/packages/realtime-compiler/src/Routing/PageRouter.php @@ -8,6 +8,8 @@ use Hyde\Pages\Concerns\HydePage; use Hyde\RealtimeCompiler\Concerns\InteractsWithLaravel; use Hyde\RealtimeCompiler\Concerns\SendsErrorResponses; +use Hyde\RealtimeCompiler\Http\DashboardController; +use Hyde\RealtimeCompiler\Http\HtmlResponse; use Hyde\Support\Models\Route; /** @@ -28,6 +30,12 @@ public function __construct(Request $request) protected function handlePageRequest(): Response { + if ($this->request->path === '/dashboard' && DashboardController::enabled()) { + return new HtmlResponse(200, 'OK', [ + 'body' => (new DashboardController())->show(), + ]); + } + $html = $this->getHtml(Route::getOrFail($this->normalizePath($this->request->path))->getPage()); return (new Response(200, 'OK', [ @@ -55,6 +63,10 @@ protected function normalizePath(string $path): string protected function getHtml(HydePage $page): string { + if ($page->identifier === 'index' && DashboardController::enabled()) { + return DashboardController::renderIndexPage($page); + } + return file_get_contents((new StaticPageBuilder($page))->__invoke()); }