Skip to content

Commit

Permalink
Merge pull request #579 from hydephp/develop
Browse files Browse the repository at this point in the history
HydePHP v1.2.0 - 2023-06-22
  • Loading branch information
caendesilva authored Jun 22, 2023
2 parents 7dd4ff1 + 98c21f1 commit 1683b8d
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 49 deletions.
15 changes: 15 additions & 0 deletions config/markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,19 @@
*/

'enable_blade' => false,

/*
|--------------------------------------------------------------------------
| Tailwind Typography Prose Classes
|--------------------------------------------------------------------------
|
| HydePHP uses Tailwind Typography to style rendered Markdown.
|
| This setting controls the base classes to apply to all the HTML elements
| containing rendered markdown. Please note that if you add any new
| classes, you may need to recompile your CSS file.
|
*/

'prose_classes' => 'prose dark:prose-invert',
];
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
@endphp

<article id="document" itemscope itemtype="https://schema.org/Article" @class([
'mx-auto lg:ml-8 prose dark:prose-invert max-w-3xl p-12 md:px-16 max-w-[1000px] min-h-[calc(100vh_-_4rem)]',
'mx-auto lg:ml-8 max-w-3xl p-12 md:px-16 max-w-[1000px] min-h-[calc(100vh_-_4rem)]',
config('markdown.prose_classes', 'prose dark:prose-invert'),
'torchlight-enabled' => $document->hasTorchlight()])>
@yield('content')

Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/post/article.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<article aria-label="Article" id="{{ $page->identifier }}" itemscope
itemtype="https://schema.org/Article"
@class(['post-article mx-auto prose dark:prose-invert', 'torchlight-enabled' => Hyde\Facades\Features::hasTorchlight()])>
@class(['post-article mx-auto', config('markdown.prose_classes', 'prose dark:prose-invert'), 'torchlight-enabled' => Features::hasTorchlight()])>
<meta itemprop="identifier" content="{{ $page->identifier }}">
@if($page->getCanonicalUrl() !== null)
<meta itemprop="url" content="{{ $page->getCanonicalUrl() }}">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@section('content')

<main id="content" class="mx-auto max-w-7xl py-16 px-8">
<article @class(['mx-auto prose dark:prose-invert', 'torchlight-enabled' => Features::hasTorchlight()])>
<article @class(['mx-auto', config('markdown.prose_classes', 'prose dark:prose-invert'), 'torchlight-enabled' => Features::hasTorchlight()])>
{{ $content }}
</article>
</main>
Expand Down
37 changes: 20 additions & 17 deletions src/Console/Commands/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,42 @@ public function __construct()
public function handle(): int
{
$this->info('HydePHP Debug Screen');

$this->newLine();

$this->comment('Git Version: '.(string) app('git.version'));
$this->comment('Hyde Version: '.(InstalledVersions::getPrettyVersion('hyde/hyde') ?: 'unreleased'));
$this->comment('Hyde Version: '.((InstalledVersions::isInstalled('hyde/hyde') ? InstalledVersions::getPrettyVersion('hyde/hyde') : null) ?: 'unreleased'));
$this->comment('Framework Version: '.(InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased'));

$this->newLine();
$this->comment('App Env: '.(string) app('env'));

$this->comment('App Env: '.(string) app('env'));
$this->newLine();
if ($this->getOutput()->isVerbose()) {
$this->line('Project directory:');
$this->line(' > '.realpath(Hyde::path()));
$this->line('Framework vendor path:');
$this->line(' > '.(str_replace('/', DIRECTORY_SEPARATOR, Hyde::vendorPath()).' (vendor)'));
$this->line(' > '.realpath(Hyde::vendorPath()).' (real)');

if ($this->output->isVerbose()) {
$this->printVerbosePathInformation();
} else {
$this->comment('Project directory: '.Hyde::path());
}

$this->newLine();

$this->line('Enabled features:');
foreach ($this->enabledFeatures() as $feature) {
$this->line(" - $feature");
}
$this->printEnabledFeatures();

return Command::SUCCESS;
}

/** @return array<string> */
protected function enabledFeatures(): array
protected function printVerbosePathInformation(): void
{
return Config::getArray('hyde.features');
$this->line('Project directory:');
$this->line(' > '.realpath(Hyde::path()));
$this->line('Framework vendor path:');
$this->line(' > '.(str_replace('/', DIRECTORY_SEPARATOR, Hyde::vendorPath()).' (vendor)'));
$this->line(' > '.realpath(Hyde::vendorPath()).' (real)');
}

protected function printEnabledFeatures(): void
{
foreach (Config::getArray('hyde.features') as $feature) {
$this->line(" - $feature");
}
}
}
52 changes: 43 additions & 9 deletions src/Foundation/Internal/LoadYamlConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,23 @@
use Hyde\Facades\Config;
use Symfony\Component\Yaml\Yaml;

use function array_key_first;
use function file_get_contents;
use function array_merge;
use function file_exists;

/**
* @internal
* @internal Bootstrap service that loads the YAML configuration file.
*
* @see docs/digging-deeper/customization.md#yaml-configuration
*
* It also supports loading multiple configuration namespaces, where a configuration namespace is defined
* as the first level in the service container configuration repository array, and usually corresponds
* one-to-one with a file in the config directory. This feature, by design, requires a top-level
* configuration entry to be present as 'hyde' in the YAML file. Existing config files
* will be parsed as normal, but can be migrated by indenting all entries by one
* level, and adding a top-level 'hyde' key. Then additional namespaces can
* be added underneath as needed.
*/
class LoadYamlConfiguration
{
Expand All @@ -34,14 +45,6 @@ protected function hasYamlConfigFile(): bool
|| file_exists(Hyde::path('hyde.yaml'));
}

protected function mergeParsedConfiguration(): void
{
Config::set('hyde', array_merge(
Config::getArray('hyde', []),
$this->getYaml()
));
}

protected function getYaml(): array
{
return (array) Yaml::parse(file_get_contents($this->getFile()));
Expand All @@ -53,4 +56,35 @@ protected function getFile(): string
? Hyde::path('hyde.yml')
: Hyde::path('hyde.yaml');
}

protected function mergeParsedConfiguration(): void
{
$yaml = $this->getYaml();

// If the Yaml file contains namespaces, we merge those using more granular logic
// that only applies the namespace data to each configuration namespace.
if ($this->configurationContainsNamespaces($yaml)) {
foreach ($yaml as $namespace => $data) {
$this->mergeConfiguration($namespace, (array) $data);
}

return;
}

// Otherwise, we can merge using the default strategy, which is simply applying all the data to the hyde namespace.
$this->mergeConfiguration('hyde', $yaml);
}

protected function mergeConfiguration(string $namespace, array $yamlData): void
{
Config::set($namespace, array_merge(
Config::getArray($namespace, []),
$yamlData
));
}

protected function configurationContainsNamespaces(array $yaml): bool
{
return array_key_first($yaml) === 'hyde';
}
}
4 changes: 2 additions & 2 deletions src/Markdown/Models/FrontMatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public function __toString(): string
return (new ConvertsArrayToFrontMatter())->execute($this->data);
}

/** @return mixed|static */
/** @return mixed|array */
public function __get(string $key): mixed
{
return $this->get($key);
}

/** @return mixed|static */
/** @return mixed|array */
public function get(string $key = null, mixed $default = null): mixed
{
if ($key) {
Expand Down
4 changes: 2 additions & 2 deletions src/Pages/Concerns/HydePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function isDiscoverable(): bool
*
* @throws \Hyde\Framework\Exceptions\FileNotFoundException If the page does not exist.
*/
public static function get(string $identifier): HydePage
public static function get(string $identifier): static
{
return Pages::getPage(static::sourcePath($identifier));
}
Expand All @@ -118,7 +118,7 @@ public static function get(string $identifier): HydePage
*
* @throws \Hyde\Framework\Exceptions\FileNotFoundException If the file does not exist.
*/
public static function parse(string $identifier): HydePage
public static function parse(string $identifier): static
{
return (new SourceFileParser(static::class, $identifier))->get();
}
Expand Down
Loading

0 comments on commit 1683b8d

Please sign in to comment.