Skip to content

Commit 9fd6d3c

Browse files
author
Jérôme Poskin
committed
Add images to sitemap generation
1 parent bf91706 commit 9fd6d3c

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed
Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
33
{% for url in sitemap.urls %}
4-
<url>
5-
<loc>{{ url.loc }}</loc>
6-
{% if url.lastmod is defined %}
7-
<lastmod>{{ url.lastmod|date(constant('DATE_W3C')) }}</lastmod>
8-
{% endif %}
9-
{% if url.changefreq is defined %}
10-
<changefreq>{{ url.changefreq }}</changefreq>
11-
{% endif %}
12-
{% if url.priority is defined %}
13-
<priority>{{ url.priority }}</priority>
14-
{% endif %}
15-
</url>
4+
<url>
5+
<loc>{{ url.loc }}</loc>
6+
{% if url.lastmod is defined %}
7+
<lastmod>{{ url.lastmod|date(constant('DATE_W3C')) }}</lastmod>
8+
{% endif %}
9+
{% if url.changefreq is defined %}
10+
<changefreq>{{ url.changefreq }}</changefreq>
11+
{% endif %}
12+
{% if url.priority is defined %}
13+
<priority>{{ url.priority }}</priority>
14+
{% endif %}
15+
{% if url.images is defined %}
16+
{% for image in url.images %}
17+
<image:image>
18+
{% if image.path is defined %}
19+
<image:loc>{{ image.path }}</image:loc>
20+
{% endif %}
21+
{% if image.path is defined %}
22+
<image:caption>{{ image.caption }}</image:caption>
23+
{% endif %}
24+
{% if image.geo_location is defined %}
25+
<image:geo_location>{{ image.geo_location }}</image:geo_location>
26+
{% endif %}
27+
{% if image.title is defined %}
28+
<image:title>{{ image.title }}</image:title>
29+
{% endif %}
30+
{% if image.licence is defined %}
31+
<image:licence>{{ image.licence }}</image:licence>
32+
{% endif %}
33+
</image:image>
34+
{% endfor %}
35+
{% endif %}
36+
</url>
1637
{% endfor %}
1738
</urlset>

Sitemap/AbstractSitemap.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ abstract class AbstractSitemap
3030
* @param \DateTime $lastMod
3131
* @param string $changeFreq
3232
* @param mixed $priority
33+
* @param array $images
3334
* @return AbstractSitemap
3435
*/
35-
protected function addUrl($loc, \DateTime $lastMod = null, $changeFreq = null, $priority = null)
36+
protected function addUrl($loc, \DateTime $lastMod = null, $changeFreq = null, $priority = null, $images = array())
3637
{
3738
$url = array(
3839
'loc' => $loc
@@ -48,6 +49,10 @@ protected function addUrl($loc, \DateTime $lastMod = null, $changeFreq = null, $
4849
$this->validatePriority($priority);
4950
$url['priority'] = $priority;
5051
}
52+
foreach ($images as $image) {
53+
$url['images'][] = $image;
54+
}
55+
5156
$this->urls[] = $url;
5257
return $this;
5358
}

0 commit comments

Comments
 (0)