Skip to content

Commit

Permalink
Add video tags as separate list (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Briareos17 authored Oct 18, 2023
1 parent 4efc936 commit 5f8bef3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
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

0 comments on commit 5f8bef3

Please sign in to comment.