Skip to content

Commit 7d54c84

Browse files
authored
Merge pull request #5 from Astrotomic/ft-plain-structured-properties
allow og:image instead of og:image:url
2 parents d0d7383 + 8075390 commit 7d54c84

18 files changed

+58
-32
lines changed

src/Type.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,13 @@ public function alternateLocale(string $locale)
7777
*/
7878
public function image($image)
7979
{
80-
$this->addStructuredProperty(
81-
$image instanceof Image
82-
? $image
83-
: Image::make($image)
84-
);
80+
if ($image instanceof Image) {
81+
$this->addStructuredProperty($image);
82+
83+
return $this;
84+
}
85+
86+
$this->addProperty('og', 'image', $image);
8587

8688
return $this;
8789
}
@@ -92,11 +94,13 @@ public function image($image)
9294
*/
9395
public function video($video)
9496
{
95-
$this->addStructuredProperty(
96-
$video instanceof Video
97-
? $video
98-
: Video::make($video)
99-
);
97+
if ($video instanceof Video) {
98+
$this->addStructuredProperty($video);
99+
100+
return $this;
101+
}
102+
103+
$this->addProperty('og', 'video', $video);
100104

101105
return $this;
102106
}
@@ -107,11 +111,13 @@ public function video($video)
107111
*/
108112
public function audio($audio)
109113
{
110-
$this->addStructuredProperty(
111-
$audio instanceof Audio
112-
? $audio
113-
: Audio::make($audio)
114-
);
114+
if ($audio instanceof Audio) {
115+
$this->addStructuredProperty($audio);
116+
117+
return $this;
118+
}
119+
120+
$this->addProperty('og', 'audio', $audio);
115121

116122
return $this;
117123
}

tests/GlobalTypesTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use Astrotomic\OpenGraph\StructuredProperties\Audio;
34
use Astrotomic\OpenGraph\Types\Article;
45
use Astrotomic\OpenGraph\Types\Book;
56
use Astrotomic\OpenGraph\Types\Profile;
@@ -68,6 +69,10 @@ public function __toString()
6869
->alternateLocale('en_GB')
6970
->siteName('Example')
7071
->image('http://www.example.com/image1.jpg')
72+
->audio(
73+
Audio::make('http://www.example.com/audio.mp3')
74+
->mimeType('audio/mp3')
75+
)
7176

7277
->publishedAt(new DateTime('2020-06-05 20:00:00'))
7378
->modifiedAt(new DateTime('2020-06-07 20:00:00'))

tests/VideoTypesTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Astrotomic\OpenGraph\StructuredProperties\Image;
4+
use Astrotomic\OpenGraph\StructuredProperties\Video;
45
use Astrotomic\OpenGraph\Types\Video\Episode;
56
use Astrotomic\OpenGraph\Types\Video\Movie;
67
use Astrotomic\OpenGraph\Types\Video\Other;
@@ -21,6 +22,7 @@
2122
->mimeType('image/jpg')
2223
->alt('Movie Wallpaper')
2324
)
25+
->video('http://www.example.com/trailer.mp4')
2426

2527
->releasedAt(new DateTime('2020-06-05'))
2628
->actor('http://www.example.com/actor1', 'role1')
@@ -80,7 +82,13 @@
8082
->alternateLocale('en_GB')
8183
->siteName('Example')
8284
->image('http://www.example.com/image1.jpg')
83-
->video('http://www.example.com/video.mp4')
85+
->video(
86+
Video::make('http://www.example.com/video.mp4')
87+
->width(1920)
88+
->height(1080)
89+
->mimeType('video/mp4')
90+
->alt('Movie Wallpaper')
91+
)
8492

8593
->releasedAt(new DateTime('2020-06-05'))
8694
->duration(60 * 3.5)

tests/__snapshots__/GlobalTypesTest__it_can_generate_article_tags__1.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
<meta property="og:locale" content="en_US">
88
<meta property="og:locale:alternate" content="en_GB">
99
<meta property="og:site_name" content="Example">
10-
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
10+
<meta property="og:image" content="http://www.example.com/image1.jpg">
11+
<meta property="og:audio:url" content="http://www.example.com/audio.mp3">
12+
<meta property="og:audio:type" content="audio/mp3">
1113
<meta property="article:published_time" content="2020-06-05T20:00:00+0000">
1214
<meta property="article:modified_time" content="2020-06-07T20:00:00+0000">
1315
<meta property="article:author" content="http://www.example.com/author">

tests/__snapshots__/GlobalTypesTest__it_can_generate_book_tags__1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta property="og:locale" content="en_US">
88
<meta property="og:locale:alternate" content="en_GB">
99
<meta property="og:site_name" content="Example">
10-
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
10+
<meta property="og:image" content="http://www.example.com/image1.jpg">
1111
<meta property="book:release_date" content="2020-06-05">
1212
<meta property="book:isbn" content="978-3-86680-192-9">
1313
<meta property="book:author" content="http://www.example.com/author">

tests/__snapshots__/GlobalTypesTest__it_can_generate_profile_tags__1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta property="og:locale" content="en_US">
88
<meta property="og:locale:alternate" content="en_GB">
99
<meta property="og:site_name" content="Example">
10-
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
10+
<meta property="og:image" content="http://www.example.com/image1.jpg">
1111
<meta property="profile:first_name" content="Jane">
1212
<meta property="profile:last_name" content="Doe">
1313
<meta property="profile:username" content="janedoe">

tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags__1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
<meta property="og:locale" content="en_US">
88
<meta property="og:locale:alternate" content="en_GB">
99
<meta property="og:site_name" content="Example">
10-
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
10+
<meta property="og:image" content="http://www.example.com/image1.jpg">
1111
</head></html>

tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags_with_conditional_callbacks__1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
<meta property="og:locale" content="en_US">
88
<meta property="og:locale:alternate" content="en_GB">
99
<meta property="og:site_name" content="Example">
10-
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
10+
<meta property="og:image" content="http://www.example.com/image1.jpg">
1111
</head></html>

tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags_with_conditional_proxies__1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
<meta property="og:locale" content="en_US">
88
<meta property="og:locale:alternate" content="en_GB">
99
<meta property="og:site_name" content="Example">
10-
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
10+
<meta property="og:image" content="http://www.example.com/image1.jpg">
1111
</head></html>

tests/__snapshots__/GlobalTypesTest__it_can_generate_website_tags_with_stringable_image__1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
<meta property="og:locale" content="en_US">
88
<meta property="og:locale:alternate" content="en_GB">
99
<meta property="og:site_name" content="Example">
10-
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
10+
<meta property="og:image" content="http://www.example.com/image1.jpg">
1111
</head></html>

0 commit comments

Comments
 (0)