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

HydePHP v1.4.0 - 2023-12-11 #585

Merged
merged 25 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d513376
Merge pull request #1431 from hydephp/navigation-discovery-improvements
invalid-email-address Nov 6, 2023
3692696
Merge pull request #1432 from hydephp/normalize-navigation-menu-confi…
invalid-email-address Nov 7, 2023
9d158d6
Merge branch 'master' into develop
caendesilva Nov 8, 2023
c1852df
Merge pull request #1435 from hydephp/update-internal-testing-scripts
invalid-email-address Nov 8, 2023
0a6c944
Merge pull request #1437 from hydephp/sync-downstream-repositories
invalid-email-address Nov 8, 2023
b177e63
Merge pull request #1438 from hydephp/dynamic-setup-php-action-versio…
invalid-email-address Nov 8, 2023
3d60d27
Merge pull request #1445 from hydephp/serve-command-tests
invalid-email-address Nov 9, 2023
c23d073
Merge pull request #1444 from hydephp/fancy-serve-command
invalid-email-address Nov 10, 2023
a29a52f
Skip test when dependent class does not exist https://github.com/hyde…
invalid-email-address Nov 10, 2023
0268b18
Merge pull request #1447 from hydephp/fancy-serve-command
invalid-email-address Nov 11, 2023
8dfa059
Merge pull request #1449 from hydephp/fancy-serve-command
invalid-email-address Nov 11, 2023
5d162ac
Merge pull request #1450 from hydephp/pass-through-settings-to-realti…
invalid-email-address Nov 12, 2023
72f51b1
Merge pull request #1453 from hydephp/pass-through-settings-to-realti…
invalid-email-address Nov 12, 2023
e288c53
Merge pull request #1458 from hydephp/realtime-compiler-live-edit
invalid-email-address Nov 14, 2023
f729bd7
Merge pull request #1472 from hydephp/add-documentation-index-page-to…
invalid-email-address Nov 26, 2023
eb44791
Merge branch 'master' into develop
caendesilva Nov 26, 2023
c03d972
Merge pull request #1477 from hydephp/documentation-sidebar-footer-co…
invalid-email-address Nov 26, 2023
66f03c8
Merge pull request #1478 from hydephp/fix-dot-notation-support-in-yam…
invalid-email-address Nov 27, 2023
e785f00
Use relative sitemap links when site URL is for localhost https://git…
invalid-email-address Nov 27, 2023
cdb2b01
Revert changes not ready for merge
invalid-email-address Nov 27, 2023
8943332
Merge pull request #1479 from hydephp/add-sitemap-fallback-for-missin…
invalid-email-address Nov 27, 2023
20276a1
Merge pull request #1481 from hydephp/customizable-automatic-sidebar-…
invalid-email-address Nov 27, 2023
5028631
Merge pull request #1485 from hydephp/refactor-internal-phar-support
invalid-email-address Dec 1, 2023
79f6317
Merge pull request #1483 from hydephp/add-open-flag-to-serve-command
invalid-email-address Dec 1, 2023
a22891a
Merge pull request #1490 from hydephp/release-v1.4.0
invalid-email-address Dec 11, 2023
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
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
Loading