Skip to content

Commit

Permalink
Merge pull request #565 from hydephp/develop
Browse files Browse the repository at this point in the history
HydePHP v1.0.0 - Release Candidate Four
  • Loading branch information
caendesilva authored Mar 12, 2023
2 parents ed118d4 + 415cd62 commit 4b0c7eb
Show file tree
Hide file tree
Showing 27 changed files with 109 additions and 183 deletions.
14 changes: 8 additions & 6 deletions config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@
|
*/

// Should the RSS feed be generated?
'generate_rss_feed' => true,
'rss' => [
// Should the RSS feed be generated?
'enabled' => true,

// What filename should the RSS file use?
'rss_filename' => 'feed.xml',
// What filename should the RSS file use?
'filename' => 'feed.xml',

// The channel description. By default this is "Site Name + RSS Feed".
// 'rss_description' => '',
// The channel description.
'description' => env('SITE_NAME', 'HydePHP').' RSS Feed',
],

/*
|--------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions resources/views/components/post/article.blade.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<article aria-label="Article" id="{{ Hyde::url("posts/$page->identifier", '') }}" itemscope
<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()])>
<meta itemprop="identifier" content="{{ $page->identifier }}">
@if(Hyde::hasSiteUrl())
<meta itemprop="url" content="{{ Hyde::url('posts/' . $page->identifier) }}">
@if($page->getCanonicalUrl() !== null)
<meta itemprop="url" content="{{ $page->getCanonicalUrl() }}">
@endif

<header aria-label="Header section" role="doc-pageheader">
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static function rss(): bool
{
return static::resolveMockedInstance('rss') ?? Hyde::hasSiteUrl()
&& static::hasMarkdownPosts()
&& Config::getBool('hyde.generate_rss_feed', true)
&& Config::getBool('hyde.rss.enabled', true)
&& extension_loaded('simplexml')
&& count(MarkdownPost::files()) > 0;
}
Expand Down
7 changes: 3 additions & 4 deletions src/Foundation/Facades/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Hyde\Foundation\Kernel\RouteCollection;
use Hyde\Hyde;
use Hyde\Support\Models\Route;
use Hyde\Support\Models\RouteKey;
use Illuminate\Support\Facades\Facade;

/**
Expand All @@ -28,18 +27,18 @@ public static function getFacadeRoot(): RouteCollection

public static function exists(string $routeKey): bool
{
return static::getFacadeRoot()->has(RouteKey::normalize($routeKey));
return static::getFacadeRoot()->has($routeKey);
}

public static function get(string $routeKey): ?Route
{
return static::getFacadeRoot()->get(RouteKey::normalize($routeKey));
return static::getFacadeRoot()->get($routeKey);
}

/** @throws \Hyde\Framework\Exceptions\RouteNotFoundException */
public static function getOrFail(string $routeKey): Route
{
return static::getFacadeRoot()->getRoute(RouteKey::normalize($routeKey));
return static::getFacadeRoot()->getRoute($routeKey);
}

/** @return \Hyde\Foundation\Kernel\RouteCollection<\Hyde\Support\Models\Route> */
Expand Down
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.0.0-RC.3';
final public const VERSION = '1.0.0-RC.4';

protected static self $instance;

Expand Down
6 changes: 0 additions & 6 deletions src/Framework/Actions/CreatesNewPageSourceFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ public function save(): string
return $this->outputPath;
}

/** @deprecated This method may be removed as the save method now returns the path. */
public function getOutputPath(): string
{
return $this->outputPath;
}

protected function parseTitle(string $title): string
{
return Str::afterLast($title, '/');
Expand Down
23 changes: 1 addition & 22 deletions src/Framework/Factories/HydePageDataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class HydePageDataFactory extends Concerns\PageDataFactory implements PageSchema
final public const SCHEMA = PageSchema::PAGE_SCHEMA;

protected readonly string $title;
protected readonly ?string $canonicalUrl;
protected readonly ?NavigationData $navigation;
private readonly string $routeKey;
private readonly string $outputPath;
Expand All @@ -45,18 +44,16 @@ public function __construct(private readonly CoreDataObject $pageData)
$this->routeKey = $this->pageData->routeKey;

$this->title = $this->makeTitle();
$this->canonicalUrl = $this->makeCanonicalUrl();
$this->navigation = $this->makeNavigation();
}

/**
* @return array{title: string, canonicalUrl: string|null, navigation: \Hyde\Framework\Features\Navigation\NavigationData|null}
* @return array{title: string, navigation: \Hyde\Framework\Features\Navigation\NavigationData|null}
*/
public function toArray(): array
{
return [
'title' => $this->title,
'canonicalUrl' => $this->canonicalUrl,
'navigation' => $this->navigation,
];
}
Expand All @@ -66,11 +63,6 @@ protected function makeTitle(): string
return trim($this->findTitleForPage());
}

protected function makeCanonicalUrl(): ?string
{
return $this->getCanonicalUrl();
}

protected function makeNavigation(): NavigationData
{
return NavigationData::make((new NavigationDataFactory($this->pageData, $this->title))->toArray());
Expand Down Expand Up @@ -105,17 +97,4 @@ private function findTitleFromParentIdentifier(): ?string

return null;
}

private function getCanonicalUrl(): ?string
{
if (! empty($this->matter('canonicalUrl'))) {
return $this->matter('canonicalUrl');
}

if (Hyde::hasSiteUrl() && ! empty($this->identifier)) {
return Hyde::url($this->outputPath);
}

return null;
}
}
10 changes: 5 additions & 5 deletions src/Framework/Features/Metadata/PageMetadataBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ protected function generate(): void

protected function addDynamicPageMetadata(HydePage $page): void
{
if ($page->has('canonicalUrl')) {
$this->add(Meta::link('canonical', $page->data('canonicalUrl')));
if ($page->getCanonicalUrl()) {
$this->add(Meta::link('canonical', $page->getCanonicalUrl()));
}

if ($page->has('title')) {
Expand All @@ -47,10 +47,10 @@ protected function addMetadataForMarkdownPost(MarkdownPost $page): void
$this->addPostMetadataIfExists($page, 'description');
$this->addPostMetadataIfExists($page, 'author');
$this->addPostMetadataIfExists($page, 'category', 'keywords');
$this->addPostMetadataIfExists($page, 'canonicalUrl', 'url');

if ($page->has('canonicalUrl')) {
$this->add(Meta::property('url', $page->data('canonicalUrl')));
if ($page->getCanonicalUrl()) {
$this->add(Meta::name('url', $page->getCanonicalUrl()));
$this->add(Meta::property('url', $page->getCanonicalUrl()));
}

if ($page->has('date')) {
Expand Down
10 changes: 5 additions & 5 deletions src/Framework/Features/XmlGenerators/RssFeedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ protected function addItem(MarkdownPost $post): void

protected function addDynamicItemData(SimpleXMLElement $item, MarkdownPost $post): void
{
if (isset($post->canonicalUrl)) {
$this->addChild($item, 'link', $post->canonicalUrl);
$this->addChild($item, 'guid', $post->canonicalUrl);
if ($post->getCanonicalUrl() !== null) {
$this->addChild($item, 'link', $post->getCanonicalUrl());
$this->addChild($item, 'guid', $post->getCanonicalUrl());
}

if (isset($post->date)) {
Expand Down Expand Up @@ -110,11 +110,11 @@ protected function getImageLength(FeaturedImage $image): string

public static function getFilename(): string
{
return Config::getString('hyde.rss_filename', 'feed.xml');
return Config::getString('hyde.rss.filename', 'feed.xml');
}

public static function getDescription(): string
{
return Config::getString('hyde.rss_description', Site::name().' RSS Feed');
return Config::getString('hyde.rss.description', Site::name().' RSS Feed');
}
}
2 changes: 1 addition & 1 deletion src/Markdown/Contracts/FrontMatter/PageSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface PageSchema extends FrontMatterSchema
{
public const PAGE_SCHEMA = [
'title' => 'string',
'canonicalUrl' => 'string', // DEPRECATED
'canonicalUrl' => 'string', // While not present in the page data, it is supported as a front matter key for the accessor data source.
'navigation' => NavigationSchema::NAVIGATION_SCHEMA,
];
}
20 changes: 14 additions & 6 deletions src/Pages/Concerns/HydePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,12 @@ abstract class HydePage implements PageSchema, SerializableContract

public readonly string $identifier;
public readonly string $routeKey;
public readonly string $title;

public FrontMatter $matter;
public PageMetadataBag $metadata;
public NavigationData $navigation;

public readonly string $title;

/** @deprecated v1.0.0-RC.3 - This property requires information that is setup-dependent, and will work better through a runtime accessor. Since it is mainly related to blog posts, it will be moved there. */
public ?string $canonicalUrl;

public static function make(string $identifier = '', FrontMatter|array $matter = []): static
{
return new static($identifier, $matter);
Expand Down Expand Up @@ -260,7 +256,6 @@ public function toArray(): array
'metadata' => $this->metadata,
'navigation' => $this->navigation,
'title' => $this->title,
'canonicalUrl' => $this->canonicalUrl,
];
}

Expand Down Expand Up @@ -383,6 +378,19 @@ public function navigationMenuGroup(): ?string
return $this->navigation->group;
}

public function getCanonicalUrl(): ?string
{
if (! empty($this->matter('canonicalUrl'))) {
return $this->matter('canonicalUrl');
}

if (Hyde::hasSiteUrl() && ! empty($this->identifier)) {
return Hyde::url($this->getOutputPath());
}

return null;
}

protected function constructMetadata(): void
{
$this->metadata = new PageMetadataBag($this);
Expand Down
8 changes: 0 additions & 8 deletions src/Support/Filesystem/SourceFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Hyde\Support\Filesystem;

use Hyde\Pages\Concerns\HydePage;
use Illuminate\Support\Str;

/**
* File abstraction for a project source file.
Expand Down Expand Up @@ -40,11 +39,4 @@ public function toArray(): array
'pageClass' => $this->pageClass,
]);
}

/** @deprecated This method is not used anywhere other than tests and may be removed */
public function withoutDirectoryPrefix(): string
{
// Works like basename, but keeps subdirectory names.
return Str::after($this->path, $this->pageClass::sourceDirectory().'/');
}
}
21 changes: 0 additions & 21 deletions src/Support/Models/RenderData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Facades\View;
use InvalidArgumentException;
use JetBrains\PhpStorm\Deprecated;

/**
* Contains data for the current page being rendered/compiled.
Expand Down Expand Up @@ -38,31 +37,11 @@ public function getPage(): ?HydePage
return $this->page ?? null;
}

/**
* @deprecated v1.0.0-RC.2 - Renamed to getRoute() to match renamed property. This method will be removed before version 1.0.
* @codeCoverageIgnore
*/
#[Deprecated(reason: 'Renamed to getRoute() to match renamed property. This method will be removed before version 1.0.', replacement: '%class%->getRoute()')]
public function getCurrentRoute(): ?Route
{
return $this->getRoute();
}

public function getRoute(): ?Route
{
return $this->route ?? null;
}

/**
* @deprecated v1.0.0-RC.2 - Renamed to getRouteKey() to match renamed property. This method will be removed before version 1.0.
* @codeCoverageIgnore
*/
#[Deprecated(reason: 'Renamed to getRoute() to match renamed property. This method will be removed before version 1.0.', replacement: '%class%->getRouteKey()')]
public function getCurrentPage(): ?string
{
return $this->getRouteKey();
}

public function getRouteKey(): ?string
{
return $this->routeKey ?? null;
Expand Down
8 changes: 1 addition & 7 deletions src/Support/Models/RouteKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function make(string $key): self

public function __construct(string $key)
{
$this->key = self::normalize($key);
$this->key = $key;
}

public function __toString(): string
Expand All @@ -43,12 +43,6 @@ public function get(): string
return $this->key;
}

/** @deprecated v1.0.0-RC.2 - This method will be removed before v1.0.0 */
public static function normalize(string $string): string
{
return $string;
}

/** @param class-string<\Hyde\Pages\Concerns\HydePage> $pageClass */
public static function fromPage(string $pageClass, string $identifier): self
{
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/Actions/CreatesNewPageSourceFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ public function test_that_the_file_path_can_be_returned()
{
$this->assertSame(
Hyde::path('_pages/test-page.md'),
(new CreatesNewPageSourceFile('Test Page'))->getOutputPath()
(new CreatesNewPageSourceFile('Test Page'))->save()
);

$this->assertSame(
Hyde::path('_pages/test-page.blade.php'),
(new CreatesNewPageSourceFile('Test Page', BladePage::class))->getOutputPath()
(new CreatesNewPageSourceFile('Test Page', BladePage::class))->save()
);

// Filesystem::unlink('_pages/test-page.md');
// Filesystem::unlink('_pages/test-page.blade.php');
Filesystem::unlink('_pages/test-page.md');
Filesystem::unlink('_pages/test-page.blade.php');
}

public function test_file_is_created_using_slug_generated_from_title()
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Commands/BuildRssFeedCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BuildRssFeedCommandTest extends TestCase
public function test_rss_feed_is_generated_when_conditions_are_met()
{
config(['hyde.url' => 'https://example.com']);
config(['hyde.generate_rss_feed' => true]);
config(['hyde.rss.enabled' => true]);
$this->file('_posts/foo.md');

$this->assertFileDoesNotExist(Hyde::path('_site/feed.xml'));
Expand All @@ -30,8 +30,8 @@ public function test_rss_feed_is_generated_when_conditions_are_met()
public function test_rss_filename_can_be_changed()
{
config(['hyde.url' => 'https://example.com']);
config(['hyde.generate_rss_feed' => true]);
config(['hyde.rss_filename' => 'blog.xml']);
config(['hyde.rss.enabled' => true]);
config(['hyde.rss.filename' => 'blog.xml']);
$this->file('_posts/foo.md');

$this->assertFileDoesNotExist(Hyde::path('_site/feed.xml'));
Expand Down
Loading

0 comments on commit 4b0c7eb

Please sign in to comment.