-
-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add video tags as separate list * Add Google News support Update snapshots * Add Google News support Update snapshots * Add Google News support Update snapshots
- Loading branch information
1 parent
5d008ae
commit 3aa65eb
Showing
27 changed files
with
173 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<news:news> | ||
<news:publication> | ||
<news:name>{{ $news->name }}</news:name> | ||
<news:language>{{ $news->language }}</news:language> | ||
</news:publication> | ||
<news:title>{{ $news->title }}</news:title> | ||
<news:publication_date>{{ $news->publicationDate->toW3cString() }}</news:publication_date> | ||
@foreach($news->options as $tag => $value) | ||
<news:{{$tag}}>{{$value}}</news:{{$tag}}> | ||
@endforeach | ||
</news:news> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace Spatie\Sitemap\Tags; | ||
|
||
use Carbon\Carbon; | ||
use DateTimeInterface; | ||
|
||
class News | ||
{ | ||
public const OPTION_ACCESS_SUB = 'Subscription'; | ||
public const OPTION_ACCESS_REG = 'Registration'; | ||
|
||
public const OPTION_GENRES_PR = 'PressRelease'; | ||
public const OPTION_GENRES_SATIRE = 'Satire'; | ||
public const OPTION_GENRES_BLOG = 'Blog'; | ||
public const OPTION_GENRES_OPED = 'OpEd'; | ||
public const OPTION_GENRES_OPINION = 'Opinion'; | ||
public const OPTION_GENRES_UG = 'UserGenerated'; | ||
|
||
public string $name; | ||
|
||
public string $language; | ||
|
||
public string $title; | ||
|
||
public Carbon $publicationDate; | ||
|
||
public ?array $options; | ||
|
||
public function __construct( | ||
string $name, | ||
string $language, | ||
string $title, | ||
DateTimeInterface $publicationDate, | ||
array $options = [] | ||
) { | ||
$this | ||
->setName($name) | ||
->setLanguage($language) | ||
->setTitle($title) | ||
->setPublicationDate($publicationDate) | ||
->setOptions($options); | ||
} | ||
|
||
public function setName(string $name): self | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
public function setLanguage(string $language): self | ||
{ | ||
$this->language = $language; | ||
|
||
return $this; | ||
} | ||
|
||
public function setTitle(string $title): self | ||
{ | ||
$this->title = $title; | ||
|
||
return $this; | ||
} | ||
|
||
public function setPublicationDate(DateTimeInterface $publicationDate): self | ||
{ | ||
$this->publicationDate = Carbon::instance($publicationDate); | ||
|
||
return $this; | ||
} | ||
|
||
public function setOptions(array $options): self | ||
{ | ||
$this->options = $options; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
use Carbon\Carbon; | ||
use Spatie\Sitemap\Sitemap; | ||
use Spatie\Sitemap\Tags\News; | ||
use Spatie\Sitemap\Tags\Url; | ||
|
||
test('XML has News tag', function () { | ||
$publicationDate = Carbon::now(); | ||
$expected_xml = '<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"> | ||
<url> | ||
<loc>https://example.com</loc> | ||
<changefreq>daily</changefreq> | ||
<priority>0.8</priority> | ||
<news:news> | ||
<news:publication> | ||
<news:name>News name</news:name> | ||
<news:language>en</news:language> | ||
</news:publication> | ||
<news:title>New news article</news:title> | ||
<news:publication_date>'.$publicationDate->toW3cString().'</news:publication_date> | ||
<news:access>Subscription</news:access> | ||
<news:genres>Blog, UserGenerated</news:genres> | ||
</news:news> | ||
</url> | ||
</urlset>'; | ||
|
||
$options = [ | ||
'access' => News::OPTION_ACCESS_SUB, | ||
'genres' => implode(', ', [News::OPTION_GENRES_BLOG, News::OPTION_GENRES_UG]) | ||
]; | ||
$sitemap = Sitemap::create() | ||
->add( | ||
Url::create("https://example.com") | ||
->addNews('News name', 'en', 'New news article', $publicationDate, $options) | ||
); | ||
|
||
$render_output = $sitemap->render(); | ||
|
||
expect($render_output)->toEqualXmlString($expected_xml); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapGeneratorTest__it_can_generate_a_sitemap__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...__/SitemapGeneratorTest__it_can_modify_the_attributes_while_generating_the_sitemap__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapGeneratorTest__it_can_use_a_custom_profile__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...torTest__it_will_not_add_the_url_to_the_sitemap_if_hasCrawled()_does_not_return_it__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ts__/SitemapGeneratorTest__it_will_not_crawl_an_url_of_shouldCrawl()_returns_false__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__a_url_object_cannot_be_added_twice_to_the_sitemap__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__an_url_cannot_be_added_twice_to_the_sitemap__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__an_url_object_can_be_added_to_the_sitemap__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__an_url_string_can_be_added_to_the_sitemap__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__an_url_with_an_alternate_can_be_added_to_the_sitemap__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__it_can_render_an_empty_sitemap__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"> | ||
</urlset> |
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__it_can_render_an_url_with_all_its_set_properties__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__it_can_render_an_url_with_priority_0__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__it_can_write_a_sitemap_to_a_file__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"> | ||
</urlset> |
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__it_can_write_a_sitemap_to_a_storage_disk__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9"> | ||
</urlset> |
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_in_one_call__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tests/__snapshots__/SitemapTest__multiple_urls_can_be_added_to_the_sitemap__1.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.