Skip to content

Commit

Permalink
Merge branch 'master' into 2.x-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jun 23, 2024
2 parents f4e4870 + e4dcb81 commit 19a3878
Show file tree
Hide file tree
Showing 19 changed files with 779 additions and 469 deletions.
2 changes: 0 additions & 2 deletions .idea/develop.iml

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

14 changes: 7 additions & 7 deletions composer.lock

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

70 changes: 35 additions & 35 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hydefront": "^3.3.0",
"laravel-mix": "^6.0.49",
"postcss": "^8.4.38",
"prettier": "3.3.0",
"tailwindcss": "^3.4.3"
"prettier": "3.3.2",
"tailwindcss": "^3.4.4"
}
}
2 changes: 1 addition & 1 deletion packages/framework/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"illuminate/view": "^10.0",
"symfony/yaml": "^6.0",
"league/commonmark": "^2.2",
"spatie/yaml-front-matter": "^2.0.7",
"spatie/yaml-front-matter": "^2.0.9",
"torchlight/torchlight-commonmark": "^0.5.5"
},
"suggest": {
Expand Down
24 changes: 17 additions & 7 deletions packages/framework/src/Console/Commands/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
namespace Hyde\Console\Commands;

use Hyde\Hyde;
use Illuminate\Support\Arr;
use Hyde\Console\Concerns\Command;
use Hyde\Support\Internal\RouteListItem;

use function array_map;
use function array_keys;
use function json_encode;
use function array_values;

/**
Expand All @@ -18,7 +19,7 @@
class RouteListCommand extends Command
{
/** @var string */
protected $signature = 'route:list';
protected $signature = 'route:list {--format=txt : The output format (txt or json)}';

/** @var string */
protected $description = 'Display all the registered routes';
Expand All @@ -27,20 +28,29 @@ public function handle(): int
{
$routes = $this->generate();

$this->table($this->makeHeader($routes), $routes);

return Command::SUCCESS;
return match ($this->option('format')) {
'txt' => $this->table($this->makeHeader($routes), $routes) ?? Command::SUCCESS,
'json' => $this->writeRaw(json_encode($routes, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) ?? Command::SUCCESS,
default => $this->error("Invalid format provided. Only 'txt' and 'json' are supported.") ?? Command::FAILURE,
};
}

/** @return array<integer, array<string, string>> */
protected function generate(): array
{
return array_map(RouteListItem::format(...), array_values(Hyde::routes()->all()));
return Arr::map(array_values(Hyde::routes()->all()), RouteListItem::format(...));
}

/** @param array<integer, array<string, string>> $routes */
protected function makeHeader(array $routes): array
{
return array_map(Hyde::makeTitle(...), array_keys($routes[0]));
return Arr::map(array_keys($routes[0]), Hyde::makeTitle(...));
}

/** Write a message without ANSI formatting */
protected function writeRaw(string $message): void
{
$this->output->setDecorated(false);
$this->output->writeln($message);
}
}
19 changes: 15 additions & 4 deletions packages/framework/src/Foundation/Kernel/Hyperlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,27 +126,38 @@ public function asset(string $name, bool $preferQualifiedUrl = false): string

/**
* Check if a site base URL has been set in config (or .env).
*
* The default value is `http://localhost`, which is not considered a valid site URL.
*/
public function hasSiteUrl(): bool
{
return ! blank(Config::getNullableString('hyde.url'));
$value = Config::getNullableString('hyde.url');

return ! blank($value) && $value !== 'http://localhost';
}

/**
* Return a qualified URL to the supplied path if a base URL is set.
*
* @param string $path optional relative path suffix. Omit to return base url.
* @param string $path An optional relative path suffix. Omit to return the base URL.
*
* @throws BaseUrlNotSetException If no site URL is set and no default is provided
* @throws BaseUrlNotSetException If no site URL is set and no path is provided.
*/
public function url(string $path = ''): string
{
$path = $this->formatLink(trim($path, '/'));

if ($this->hasSiteUrl()) {
return rtrim(rtrim((string) Config::getNullableString('hyde.url'), '/')."/$path", '/');
return rtrim(rtrim(Config::getString('hyde.url'), '/')."/$path", '/');
}

// Since v1.7.0, we return the relative path even if the base URL is not set,
// as this is more likely to be the desired behavior the user's expecting.
if (! blank($path)) {
return $path;
}

// User is trying to get the base URL, but it's not set
throw new BaseUrlNotSetException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Hyde\Framework\Concerns\InteractsWithDirectories;
use Hyde\Framework\Features\XmlGenerators\SitemapGenerator;

use function blank;
use function file_put_contents;

class GenerateSitemap extends PostBuildTask
Expand All @@ -22,7 +21,7 @@ class GenerateSitemap extends PostBuildTask

public function handle(): void
{
if (blank(Hyde::url()) || str_starts_with(Hyde::url(), 'http://localhost')) {
if (! Hyde::hasSiteUrl()) {
$this->skip('Cannot generate sitemap without a valid base URL');
}

Expand Down
6 changes: 3 additions & 3 deletions packages/framework/src/Support/DataCollections.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function markdown(string $name): static
{
static::needsDirectory(static::$sourceDirectory);

return new static(DataCollections::findFiles($name, 'md')->mapWithKeys(function (string $file): array {
return new static(static::findFiles($name, 'md')->mapWithKeys(function (string $file): array {
return [static::makeIdentifier($file) => MarkdownFileParser::parse($file)];
}));
}
Expand All @@ -67,7 +67,7 @@ public static function yaml(string $name): static
{
static::needsDirectory(static::$sourceDirectory);

return new static(DataCollections::findFiles($name, ['yaml', 'yml'])->mapWithKeys(function (string $file): array {
return new static(static::findFiles($name, ['yaml', 'yml'])->mapWithKeys(function (string $file): array {
return [static::makeIdentifier($file) => MarkdownFileParser::parse($file)->matter()];
}));
}
Expand All @@ -83,7 +83,7 @@ public static function json(string $name, bool $asArray = false): static
{
static::needsDirectory(static::$sourceDirectory);

return new static(DataCollections::findFiles($name, 'json')->mapWithKeys(function (string $file) use ($asArray): array {
return new static(static::findFiles($name, 'json')->mapWithKeys(function (string $file) use ($asArray): array {
return [static::makeIdentifier($file) => json_decode(Filesystem::get($file), $asArray)];
}));
}
Expand Down
Loading

0 comments on commit 19a3878

Please sign in to comment.