Skip to content

Commit

Permalink
Add images to sitemap generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Poskin committed Jun 12, 2015
1 parent bf91706 commit 9fd6d3c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
47 changes: 34 additions & 13 deletions Resources/views/Sitemap/sitemap.xml.twig
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
{% for url in sitemap.urls %}
<url>
<loc>{{ url.loc }}</loc>
{% if url.lastmod is defined %}
<lastmod>{{ url.lastmod|date(constant('DATE_W3C')) }}</lastmod>
{% endif %}
{% if url.changefreq is defined %}
<changefreq>{{ url.changefreq }}</changefreq>
{% endif %}
{% if url.priority is defined %}
<priority>{{ url.priority }}</priority>
{% endif %}
</url>
<url>
<loc>{{ url.loc }}</loc>
{% if url.lastmod is defined %}
<lastmod>{{ url.lastmod|date(constant('DATE_W3C')) }}</lastmod>
{% endif %}
{% if url.changefreq is defined %}
<changefreq>{{ url.changefreq }}</changefreq>
{% endif %}
{% if url.priority is defined %}
<priority>{{ url.priority }}</priority>
{% endif %}
{% if url.images is defined %}
{% for image in url.images %}
<image:image>
{% if image.path is defined %}
<image:loc>{{ image.path }}</image:loc>
{% endif %}
{% if image.path is defined %}
<image:caption>{{ image.caption }}</image:caption>
{% endif %}
{% if image.geo_location is defined %}
<image:geo_location>{{ image.geo_location }}</image:geo_location>
{% endif %}
{% if image.title is defined %}
<image:title>{{ image.title }}</image:title>
{% endif %}
{% if image.licence is defined %}
<image:licence>{{ image.licence }}</image:licence>
{% endif %}
</image:image>
{% endfor %}
{% endif %}
</url>
{% endfor %}
</urlset>
7 changes: 6 additions & 1 deletion Sitemap/AbstractSitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ abstract class AbstractSitemap
* @param \DateTime $lastMod
* @param string $changeFreq
* @param mixed $priority
* @param array $images
* @return AbstractSitemap
*/
protected function addUrl($loc, \DateTime $lastMod = null, $changeFreq = null, $priority = null)
protected function addUrl($loc, \DateTime $lastMod = null, $changeFreq = null, $priority = null, $images = array())
{
$url = array(
'loc' => $loc
Expand All @@ -48,6 +49,10 @@ protected function addUrl($loc, \DateTime $lastMod = null, $changeFreq = null, $
$this->validatePriority($priority);
$url['priority'] = $priority;
}
foreach ($images as $image) {
$url['images'][] = $image;
}

$this->urls[] = $url;
return $this;
}
Expand Down

0 comments on commit 9fd6d3c

Please sign in to comment.