Skip to content

Commit ad7ad3c

Browse files
authored
Merge pull request #400 from hydephp/398-remove-legacy-metadata-model
Fix #398: Remove the deprecated Metadata model
2 parents d49bb6d + 9aee23c commit ad7ad3c

File tree

3 files changed

+14
-75
lines changed

3 files changed

+14
-75
lines changed

src/Concerns/GeneratesPageMetadata.php

+14-28
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Hyde\Framework\Models\MarkdownPost;
77
use Hyde\Framework\Models\Metadata;
88
use Hyde\Framework\Services\AuthorService;
9-
use JetBrains\PhpStorm\ArrayShape;
109

1110
/**
1211
* Generates metadata for page models that have front matter.
@@ -16,37 +15,26 @@
1615
*/
1716
trait GeneratesPageMetadata
1817
{
19-
public ?Metadata $metadata = null;
18+
public array $metadata = [];
19+
public array $properties = [];
2020

2121
public function constructMetadata(): void
2222
{
23-
$this->metadata = new Metadata();
24-
2523
$this->parseFrontMatterMetadata();
2624

2725
if ($this instanceof MarkdownPost || $this instanceof \Tests\TestCase) {
2826
$this->makeOpenGraphPropertiesForArticle();
2927
}
3028
}
3129

32-
#[ArrayShape(['name' => "\content"])]
3330
public function getMetadata(): array
3431
{
35-
if (! isset($this->metadata)) {
36-
return [];
37-
}
38-
39-
return $this->metadata->metadata;
32+
return $this->metadata;
4033
}
4134

42-
#[ArrayShape(['property' => 'content'])]
4335
public function getMetaProperties(): array
4436
{
45-
if (! isset($this->metadata)) {
46-
return [];
47-
}
48-
49-
return $this->metadata->properties;
37+
return $this->properties;
5038
}
5139

5240
/**
@@ -56,15 +44,15 @@ public function getMetaProperties(): array
5644
protected function parseFrontMatterMetadata(): void
5745
{
5846
if (isset($this->matter['description'])) {
59-
$this->metadata->add('description', $this->matter['description']);
47+
$this->metadata['description'] = $this->matter['description'];
6048
}
6149

6250
if (isset($this->matter['author'])) {
63-
$this->metadata->add('author', AuthorService::getAuthorName($this->matter['author']));
51+
$this->metadata['author'] = AuthorService::getAuthorName($this->matter['author']);
6452
}
6553

6654
if (isset($this->matter['category'])) {
67-
$this->metadata->add('keywords', $this->matter['category']);
55+
$this->metadata['keywords'] = $this->matter['category'];
6856
}
6957
}
7058

@@ -73,30 +61,28 @@ protected function parseFrontMatterMetadata(): void
7361
*/
7462
protected function makeOpenGraphPropertiesForArticle(): void
7563
{
76-
$this->metadata->addProperty('og:type', 'article');
77-
64+
$this->properties['og:type'] = 'article';
7865
if (Hyde::uriPath()) {
79-
$this->metadata->addProperty('og:url', Hyde::uriPath(Hyde::pageLink('posts/'.$this->slug.'.html')));
66+
$this->properties['og:url'] = Hyde::uriPath(Hyde::pageLink('posts/'.$this->slug.'.html'));
8067
}
8168

8269
if (isset($this->matter['title'])) {
83-
$this->metadata->addProperty('og:title', $this->matter['title']);
70+
$this->properties['og:title'] = $this->matter['title'];
8471
}
8572

8673
if (isset($this->matter['date'])) {
87-
$date = date('c', strtotime($this->matter['date']));
88-
$this->metadata->addProperty('og:article:published_time', $date);
74+
$this->properties['og:article:published_time'] = date('c', strtotime($this->matter['date']));
8975
}
9076

9177
if (isset($this->matter['image'])) {
9278
if (is_string($this->matter['image'])) {
93-
$this->metadata->addProperty('og:image', $this->matter['image']);
79+
$this->properties['og:image'] = $this->matter['image'];
9480
} else {
9581
if (isset($this->matter['image']['path'])) {
96-
$this->metadata->addProperty('og:image', $this->matter['image']['path']);
82+
$this->properties['og:image'] = $this->matter['image']['path'];
9783
}
9884
if (isset($this->matter['image']['uri'])) {
99-
$this->metadata->addProperty('og:image', $this->matter['image']['uri']);
85+
$this->properties['og:image'] = $this->matter['image']['uri'];
10086
}
10187
}
10288
}

src/Models/Metadata.php

-40
This file was deleted.

tests/Feature/Concerns/GeneratesPageMetadataTest.php

-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Tests\Feature\Concerns;
44

55
use Hyde\Framework\Concerns\GeneratesPageMetadata;
6-
use Hyde\Framework\Models\Metadata;
76
use Illuminate\Support\Facades\Config;
87
use Tests\TestCase;
98

@@ -27,12 +26,6 @@ protected function tearDown(): void
2726
parent::tearDown();
2827
}
2928

30-
public function test_metadata_object_can_be_constructed()
31-
{
32-
$this->constructMetadata();
33-
$this->assertInstanceOf(Metadata::class, $this->metadata);
34-
}
35-
3629
public function test_get_metadata_returns_empty_array_when_uninitialized()
3730
{
3831
$this->matter = ['description' => 'foo'];

0 commit comments

Comments
 (0)