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

Apply fixes from StyleCI #399

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Apply fixes from StyleCI
  • Loading branch information
StyleCIBot committed May 18, 2022
commit 17626684a2a952402e861405ae7de20cdcc88131
45 changes: 22 additions & 23 deletions src/Concerns/GeneratesPageMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,74 @@
use Hyde\Framework\Models\MarkdownPost;
use Hyde\Framework\Models\Metadata;
use Hyde\Framework\Services\AuthorService;
use JetBrains\PhpStorm\ArrayShape;

/**
* Generates metadata for page models that have front matter.
*
* @see \Hyde\Framework\Models\Metadata
* @see \Tests\Feature\Concerns\GeneratesPageMetadataTest
*/
* Generates metadata for page models that have front matter.
*
* @see \Hyde\Framework\Models\Metadata
* @see \Tests\Feature\Concerns\GeneratesPageMetadataTest
*/
trait GeneratesPageMetadata
{
public array $metadata = [];
public array $properties = [];

public function constructMetadata(): void
{
$this->parseFrontMatterMetadata();

if ($this instanceof MarkdownPost || $this instanceof \Tests\TestCase) {
$this->makeOpenGraphPropertiesForArticle();
}
}

public function getMetadata(): array
{
return $this->metadata;
}

public function getMetaProperties(): array
{
return $this->properties;
}

/**
* Generate metadata from the front matter that can be used in standard <meta> tags.
* This helper is page type agnostic and works with any kind of model having front matter.
*/
* Generate metadata from the front matter that can be used in standard <meta> tags.
* This helper is page type agnostic and works with any kind of model having front matter.
*/
protected function parseFrontMatterMetadata(): void
{
if (isset($this->matter['description'])) {
$this->metadata['description'] = $this->matter['description'];
}

if (isset($this->matter['author'])) {
$this->metadata['author'] = AuthorService::getAuthorName($this->matter['author']);
}

if (isset($this->matter['category'])) {
$this->metadata['keywords'] = $this->matter['category'];
}
}

/**
* Generate opengraph metadata from front matter for an og:article such as a blog post.
*/
* Generate opengraph metadata from front matter for an og:article such as a blog post.
*/
protected function makeOpenGraphPropertiesForArticle(): void
{
$this->properties['og:type'] = 'article';
if (Hyde::uriPath()) {
$this->properties['og:url'] = Hyde::uriPath(Hyde::pageLink('posts/' . $this->slug . '.html'));
$this->properties['og:url'] = Hyde::uriPath(Hyde::pageLink('posts/'.$this->slug.'.html'));
}

if (isset($this->matter['title'])) {
$this->properties['og:title'] = $this->matter['title'];
}

if (isset($this->matter['date'])) {
$this->properties['og:article:published_time'] = date('c', strtotime($this->matter['date']));
}

if (isset($this->matter['image'])) {
if (is_string($this->matter['image'])) {
$this->properties['og:image'] = $this->matter['image'];
Expand Down
1 change: 0 additions & 1 deletion tests/Feature/Concerns/GeneratesPageMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Tests\Feature\Concerns;

use Hyde\Framework\Concerns\GeneratesPageMetadata;
use Hyde\Framework\Models\Metadata;
use Illuminate\Support\Facades\Config;
use Tests\TestCase;

Expand Down