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

Add video tags as separate list #525

Merged
merged 1 commit into from
Oct 18, 2023
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
3 changes: 3 additions & 0 deletions resources/views/video.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
@foreach($video->deny as $tag => $value)
<video:{{$tag}} relationship="deny">{{$value}}</video:{{$tag}}>
@endforeach
@foreach($video->tags as $tag)
<video:tag>{{ $tag }}</video:tag>
@endforeach
</video:video>
4 changes: 2 additions & 2 deletions src/Tags/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public function addImage(string $url, string $caption = '', string $geo_location
return $this;
}

public function addVideo(string $thumbnailLoc, string $title, string $description, $contentLoc = null, $playerLoc = null, array $options = [], array $allow = [], array $deny = []): static
public function addVideo(string $thumbnailLoc, string $title, string $description, $contentLoc = null, $playerLoc = null, array $options = [], array $allow = [], array $deny = [], array $tags = []): static
{
$this->videos[] = new Video($thumbnailLoc, $title, $description, $contentLoc, $playerLoc, $options, $allow, $deny);
$this->videos[] = new Video($thumbnailLoc, $title, $description, $contentLoc, $playerLoc, $options, $allow, $deny, $tags);

return $this;
}
Expand Down
14 changes: 12 additions & 2 deletions src/Tags/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class Video

public array $deny;

public function __construct(string $thumbnailLoc, string $title, string $description, string $contentLoc = null, string $playerLoc = null, array $options = [], array $allow = [], array $deny = [])
public array $tags;

public function __construct(string $thumbnailLoc, string $title, string $description, string $contentLoc = null, string|array $playerLoc = null, array $options = [], array $allow = [], array $deny = [], array $tags = [])
{
if ($contentLoc === null && $playerLoc === null) {
// https://developers.google.com/search/docs/crawling-indexing/sitemaps/video-sitemaps
Expand All @@ -41,7 +43,8 @@ public function __construct(string $thumbnailLoc, string $title, string $descrip
->setPlayerLoc($playerLoc)
->setOptions($options)
->setAllow($allow)
->setDeny($deny);
->setDeny($deny)
->setTags($tags);
}

public function setThumbnailLoc(string $thumbnailLoc): self
Expand Down Expand Up @@ -99,4 +102,11 @@ public function setDeny(array $deny): self

return $this;
}

public function setTags(array $tags): self
{
$this->tags = array_slice($tags, 0 , 32); // maximum 32 tags allowed

return $this;
}
}
5 changes: 4 additions & 1 deletion tests/VideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@
<video:family_friendly>yes</video:family_friendly>
<video:platform relationship="allow">mobile</video:platform>
<video:restriction relationship="deny">CA</video:restriction>
<video:tag>tag1</video:tag>
<video:tag>tag2</video:tag>
</video:video>
</url>
</urlset>';

$options = ["live" => "no", "family_friendly" => "yes"];
$allow = ["platform" => Video::OPTION_PLATFORM_MOBILE];
$deny = ["restriction" => 'CA'];
$tags = ['tag1', 'tag2'];
$sitemap = Sitemap::create()
->add(
Url::create("https://example.com")
->addVideo("https://example.com/image.jpg", "My Test Title", "My Test Description", "https://example.com/video.mp4", null, $options, $allow, $deny)
->addVideo("https://example.com/image.jpg", "My Test Title", "My Test Description", "https://example.com/video.mp4", null, $options, $allow, $deny, $tags)
);

$render_output = $sitemap->render();
Expand Down