Skip to content

Commit

Permalink
Merge pull request #585 from hydephp/develop
Browse files Browse the repository at this point in the history
HydePHP v1.4.0 - 2023-12-11
  • Loading branch information
caendesilva authored Dec 11, 2023
2 parents f1fd610 + a22891a commit dfd4075
Show file tree
Hide file tree
Showing 21 changed files with 908 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@a36e1e52ff4a1c9e9c9be31551ee4712a6cb6bd0
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: fileinfo, zip
Expand Down
10 changes: 6 additions & 4 deletions config/docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
// When using a grouped sidebar, should the groups be collapsible?
'collapsible' => true,

// Should the sidebar footer be shown?
// Should the sidebar footer be shown? You can also set this to a string
// of Markdown to show in the footer. Set to `false` to disable.
'footer' => true,
],

Expand All @@ -43,10 +44,11 @@
| default to sort alphabetically. You can reorder the page identifiers
| in the list below, and the links will get sorted in that order.
|
| Internally, the items listed will get a position priority of 500 + the order its found in the list.
| Link items without an entry here will have fall back to the default priority of 999, putting them last.
| The items will get a priority of 500 plus the order its found in the list.
| Pages without a priority will fall back to the default priority of 999.
|
| You can also set explicit priorities in front matter.
| You can also set explicit priorities in front matter or by specifying
| a value to the array key in the list to override the inferred value.
|
*/

Expand Down
15 changes: 11 additions & 4 deletions config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,27 +300,31 @@
|
| If you are looking to customize the main navigation menu, this is the place!
|
| All these settings uses Route Keys to identify the page you want to configure.
| A route key is simply the URL path to the page, without the file extension.
| So `_site/posts/hello-world.html` has the route key 'posts/hello-world'.
|
*/

'navigation' => [
// This configuration sets the priorities used to determine the order of the menu.
// The default values have been added below for reference and easy editing.
// The array key should match the page's route key (slug).
// Lower values show up first in the menu.
// The array key is the page's route key, the value is the priority.
// Lower values show up first in the menu. The default is 999.
'order' => [
'index' => 0,
'posts' => 10,
'docs/index' => 100,
],

// In case you want to customize the labels for the menu items, you can do so here.
// Simply add the route key (slug) as the key, and the label as the value.
// Simply add the route key as the array key, and the label as the value.
'labels' => [
'index' => 'Home',
'docs/index' => 'Docs',
],

// These are the pages that should not show up in the navigation menu.
// These are the route keys of pages that should not show up in the navigation menu.
'exclude' => [
'404',
],
Expand Down Expand Up @@ -414,6 +418,9 @@
// Should preview pages be saved to the output directory?
'save_preview' => true,

// Should the live edit feature be enabled?
'live_edit' => env('SERVER_LIVE_EDIT', true),

// Configure the realtime compiler dashboard
'dashboard' => [
// Should the realtime compiler dashboard be enabled?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<p>
<a href="{{ Hyde::relativeLink('index.html') }}">Back to home page</a>
@if(is_bool(config('docs.sidebar.footer', true)))
<a href="{{ Hyde::relativeLink('index.html') }}">Back to home page</a>
@else
{{ Hyde::markdown(config('docs.sidebar.footer')) }}
@endif
</p>
2 changes: 1 addition & 1 deletion resources/views/components/docs/sidebar-items.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@foreach ($sidebar->getGroups() as $group)
<li class="sidebar-group" role="listitem" @if($collapsible) x-data="{ groupOpen: {{ $sidebar->isGroupActive($group) ? 'true' : 'false' }} }" @endif>
<header class="sidebar-group-header p-2 px-4 -ml-2 flex justify-between items-center @if($collapsible) group hover:bg-black/10 @endif" @if($collapsible) @click="groupOpen = ! groupOpen" @endif>
<h4 class="sidebar-group-heading text-base font-semibold @if($collapsible) cursor-pointer dark:group-hover:text-white @endif">{{ Hyde::makeTitle($group) }}</h4>
<h4 class="sidebar-group-heading text-base font-semibold @if($collapsible) cursor-pointer dark:group-hover:text-white @endif">{{ $sidebar->makeGroupTitle($group) }}</h4>
@if($collapsible)
@include('hyde::components.docs.sidebar-group-toggle-button')
@endif
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/docs/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'sidebar' => \Hyde\Framework\Features\Navigation\DocumentationSidebar::create(),
])
</nav>
@if(config('docs.sidebar.footer', true))
@if(config('docs.sidebar.footer', true) !== false)
<footer id="sidebar-footer" class="h-16 p-4 w-full bottom-0 left-0 text-center leading-8">
@include('hyde::components.docs.sidebar-footer-text')
</footer>
Expand Down
122 changes: 111 additions & 11 deletions src/Console/Commands/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

namespace Hyde\Console\Commands;

use Closure;
use Hyde\Hyde;
use Hyde\Facades\Config;
use Illuminate\Support\Arr;
use InvalidArgumentException;
use Hyde\Console\Concerns\Command;
use Hyde\RealtimeCompiler\ConsoleOutput;
use Illuminate\Support\Facades\Process;
use LaravelZero\Framework\Commands\Command;

use function sprintf;
use function str_replace;
use function class_exists;

/**
* Start the realtime compiler server.
Expand All @@ -19,14 +25,29 @@
class ServeCommand extends Command
{
/** @var string */
protected $signature = 'serve {--host= : <comment>[default: "localhost"]</comment>}} {--port= : <comment>[default: 8080]</comment>}';
protected $signature = 'serve
{--host= : <comment>[default: "localhost"]</comment>}}
{--port= : <comment>[default: 8080]</comment>}
{--save-preview= : Should the served page be saved to disk? (Overrides config setting)}
{--dashboard= : Enable the realtime compiler dashboard. (Overrides config setting)}
{--pretty-urls= : Enable pretty URLs. (Overrides config setting)}
{--play-cdn= : Enable the Tailwind Play CDN. (Overrides config setting)}
{--open : Open the site preview in the browser.}
';

/** @var string */
protected $description = 'Start the realtime compiler server.';

public function handle(): int
protected ConsoleOutput $console;

public function safeHandle(): int
{
$this->line('<info>Starting the HydeRC server...</info> Press Ctrl+C to stop');
$this->configureOutput();
$this->printStartMessage();

if ($this->option('open')) {
$this->openInBrowser();
}

$this->runServerProcess(sprintf('php -S %s:%d %s',
$this->getHostSelection(),
Expand All @@ -37,26 +58,105 @@ public function handle(): int
return Command::SUCCESS;
}

protected function getPortSelection(): int
protected function getHostSelection(): string
{
return (int) ($this->option('port') ?: Config::getInt('hyde.server.port', 8080));
return (string) $this->option('host') ?: Config::getString('hyde.server.host', 'localhost');
}

protected function getHostSelection(): string
protected function getPortSelection(): int
{
return (string) $this->option('host') ?: Config::getString('hyde.server.host', 'localhost');
return (int) ($this->option('port') ?: Config::getInt('hyde.server.port', 8080));
}

protected function getExecutablePath(): string
{
return Hyde::path('vendor/hyde/realtime-compiler/bin/server.php');
}

/** @codeCoverageIgnore Until output is testable */
protected function runServerProcess(string $command): void
{
Process::forever()->run($command, function (string $type, string $line): void {
Process::forever()->env($this->getEnvironmentVariables())->run($command, $this->getOutputHandler());
}

protected function getEnvironmentVariables(): array
{
return Arr::whereNotNull([
'HYDE_SERVER_REQUEST_OUTPUT' => ! $this->option('no-ansi'),
'HYDE_SERVER_SAVE_PREVIEW' => $this->parseEnvironmentOption('save-preview'),
'HYDE_SERVER_DASHBOARD' => $this->parseEnvironmentOption('dashboard'),
'HYDE_PRETTY_URLS' => $this->parseEnvironmentOption('pretty-urls'),
'HYDE_PLAY_CDN' => $this->parseEnvironmentOption('play-cdn'),
]);
}

protected function configureOutput(): void
{
if (! $this->useBasicOutput()) {
$this->console = new ConsoleOutput($this->output->isVerbose());
}
}

protected function printStartMessage(): void
{
$this->useBasicOutput()
? $this->output->writeln('<info>Starting the HydeRC server...</info> Press Ctrl+C to stop')
: $this->console->printStartMessage($this->getHostSelection(), $this->getPortSelection(), $this->getEnvironmentVariables());
}

protected function getOutputHandler(): Closure
{
return $this->useBasicOutput() ? function (string $type, string $line): void {
$this->output->write($line);
});
} : $this->console->getFormatter();
}

protected function useBasicOutput(): bool
{
return $this->option('no-ansi') || ! class_exists(ConsoleOutput::class);
}

protected function parseEnvironmentOption(string $name): ?string
{
$value = $this->option($name) ?? $this->checkArgvForOption($name);

if ($value !== null) {
return match ($value) {
'true', '' => 'enabled',
'false' => 'disabled',
default => throw new InvalidArgumentException(sprintf('Invalid boolean value for --%s option.', $name))
};
}

return null;
}

/** Fallback check so that an environment option without a value is acknowledged as true. */
protected function checkArgvForOption(string $name): ?string
{
if (isset($_SERVER['argv'])) {
if (in_array("--$name", $_SERVER['argv'], true)) {
return 'true';
}
}

return null;
}

protected function openInBrowser(): void
{
$command = match (PHP_OS_FAMILY) {
'Windows' => 'start',
'Darwin' => 'open',
'Linux' => 'xdg-open',
default => null
};

$process = $command ? Process::command(sprintf('%s http://%s:%d', $command, $this->getHostSelection(), $this->getPortSelection()))->run() : null;

if (! $process || $process->failed()) {
$this->warn('Unable to open the site preview in the browser on your system:');
$this->line(sprintf(' %s', str_replace("\n", "\n ", $process ? $process->errorOutput() : "Missing suitable 'open' binary.")));
$this->newLine();
}
}
}
2 changes: 1 addition & 1 deletion src/Foundation/HydeKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class HydeKernel implements SerializableContract
use Serializable;
use Macroable;

final public const VERSION = '1.3.4';
final public const VERSION = '1.4.0';

protected static self $instance;

Expand Down
Loading

0 comments on commit dfd4075

Please sign in to comment.