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

allow og:image instead of og:image:url #5

Merged
merged 3 commits into from
Jun 14, 2020
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
36 changes: 21 additions & 15 deletions src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ public function alternateLocale(string $locale)
*/
public function image($image)
{
$this->addStructuredProperty(
$image instanceof Image
? $image
: Image::make($image)
);
if ($image instanceof Image) {
$this->addStructuredProperty($image);

return $this;
}

$this->addProperty('og', 'image', $image);

return $this;
}
Expand All @@ -92,11 +94,13 @@ public function image($image)
*/
public function video($video)
{
$this->addStructuredProperty(
$video instanceof Video
? $video
: Video::make($video)
);
if ($video instanceof Video) {
$this->addStructuredProperty($video);

return $this;
}

$this->addProperty('og', 'video', $video);

return $this;
}
Expand All @@ -107,11 +111,13 @@ public function video($video)
*/
public function audio($audio)
{
$this->addStructuredProperty(
$audio instanceof Audio
? $audio
: Audio::make($audio)
);
if ($audio instanceof Audio) {
$this->addStructuredProperty($audio);

return $this;
}

$this->addProperty('og', 'audio', $audio);

return $this;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/GlobalTypesTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Astrotomic\OpenGraph\StructuredProperties\Audio;
use Astrotomic\OpenGraph\Types\Article;
use Astrotomic\OpenGraph\Types\Book;
use Astrotomic\OpenGraph\Types\Profile;
Expand Down Expand Up @@ -68,6 +69,10 @@ public function __toString()
->alternateLocale('en_GB')
->siteName('Example')
->image('http://www.example.com/image1.jpg')
->audio(
Audio::make('http://www.example.com/audio.mp3')
->mimeType('audio/mp3')
)

->publishedAt(new DateTime('2020-06-05 20:00:00'))
->modifiedAt(new DateTime('2020-06-07 20:00:00'))
Expand Down
10 changes: 9 additions & 1 deletion tests/VideoTypesTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Astrotomic\OpenGraph\StructuredProperties\Image;
use Astrotomic\OpenGraph\StructuredProperties\Video;
use Astrotomic\OpenGraph\Types\Video\Episode;
use Astrotomic\OpenGraph\Types\Video\Movie;
use Astrotomic\OpenGraph\Types\Video\Other;
Expand All @@ -21,6 +22,7 @@
->mimeType('image/jpg')
->alt('Movie Wallpaper')
)
->video('http://www.example.com/trailer.mp4')

->releasedAt(new DateTime('2020-06-05'))
->actor('http://www.example.com/actor1', 'role1')
Expand Down Expand Up @@ -80,7 +82,13 @@
->alternateLocale('en_GB')
->siteName('Example')
->image('http://www.example.com/image1.jpg')
->video('http://www.example.com/video.mp4')
->video(
Video::make('http://www.example.com/video.mp4')
->width(1920)
->height(1080)
->mimeType('video/mp4')
->alt('Movie Wallpaper')
)

->releasedAt(new DateTime('2020-06-05'))
->duration(60 * 3.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="og:audio:url" content="http://www.example.com/audio.mp3">
<meta property="og:audio:type" content="audio/mp3">
<meta property="article:published_time" content="2020-06-05T20:00:00+0000">
<meta property="article:modified_time" content="2020-06-07T20:00:00+0000">
<meta property="article:author" content="http://www.example.com/author">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="book:release_date" content="2020-06-05">
<meta property="book:isbn" content="978-3-86680-192-9">
<meta property="book:author" content="http://www.example.com/author">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="profile:first_name" content="Jane">
<meta property="profile:last_name" content="Doe">
<meta property="profile:username" content="janedoe">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
</head></html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
</head></html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
</head></html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
</head></html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="music:musician" content="http://www.example.com/musician">
<meta property="music:song" content="http://www.example.com/song1">
<meta property="music:song:disc" content="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="music:creator" content="http://www.example.com/creator">
<meta property="music:song" content="http://www.example.com/song1">
<meta property="music:song:disc" content="1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="music:creator" content="http://www.example.com/creator">
</head></html>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:audio:url" content="http://www.example.com/song.mp3">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="og:audio" content="http://www.example.com/song.mp3">
<meta property="music:duration" content="90">
<meta property="music:musician" content="http://www.example.com/musician">
<meta property="music:album" content="http://www.example.com/album">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="video:series" content="http://www.example.com/tvshow">
<meta property="video:release_date" content="2020-06-05">
<meta property="video:duration" content="1500">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="og:image:url" content="http://www.example.com/image2.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1080">
<meta property="og:image:type" content="image/jpg">
<meta property="og:image:alt" content="Movie Wallpaper">
<meta property="og:video" content="http://www.example.com/trailer.mp4">
<meta property="video:release_date" content="2020-06-05">
<meta property="video:actor" content="http://www.example.com/actor1">
<meta property="video:actor:role" content="role1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="og:video:url" content="http://www.example.com/video.mp4">
<meta property="og:video:width" content="1920">
<meta property="og:video:height" content="1080">
<meta property="og:video:type" content="video/mp4">
<meta property="og:video:alt" content="Movie Wallpaper">
<meta property="video:release_date" content="2020-06-05">
<meta property="video:duration" content="210">
<meta property="video:actor" content="http://www.example.com/actor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta property="og:locale" content="en_US">
<meta property="og:locale:alternate" content="en_GB">
<meta property="og:site_name" content="Example">
<meta property="og:image:url" content="http://www.example.com/image1.jpg">
<meta property="og:image" content="http://www.example.com/image1.jpg">
<meta property="video:release_date" content="2020-06-05">
<meta property="video:actor" content="http://www.example.com/actor">
<meta property="video:actor:role" content="role">
Expand Down