Skip to content

Commit 63aaa3d

Browse files
Merge pull request #37 from bolt/allow-ignore-images
Add 'ignore images' flag in configuration
2 parents 3ee53d8 + f448cde commit 63aaa3d

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

config/config.yml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ ignore:
1616
## ignore listing templates
1717
#ignore_listing: true
1818

19+
## ignore images (by default the sitemap contains links to images)
20+
ignore_images: false
21+
1922
## when ignore_listing is not = true: listings templates may not exist yet may contain child pages.
2023
## add path will keep listing visible in tree but remove its link.
2124
#remove_link:

src/Controller/Sitemap.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ public function sitemap(Application $app)
4747
{
4848
$config = $app['sitemap.config'];
4949
$twig = $app['twig'];
50-
$context = ['entries' => $app['sitemap.links']];
50+
$context = [
51+
'entries' => $app['sitemap.links'],
52+
'ignore_images' => $config['ignore_images'],
53+
];
54+
5155
$body = $twig->render($config['template'], $context);
5256

5357
return new Response($body, Response::HTTP_OK);
@@ -62,7 +66,11 @@ public function sitemapXml(Application $app)
6266
{
6367
$twig = $app['twig'];
6468
$config = $app['sitemap.config'];
65-
$context = ['entries' => $app['sitemap.links']];
69+
$context = [
70+
'entries' => $app['sitemap.links'],
71+
'ignore_images' => $config['ignore_images'],
72+
];
73+
6674
$body = $twig->render($config['xml_template'], $context);
6775

6876
$response = new Response($body, Response::HTTP_OK);

src/SitemapExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ protected function getDefaultConfig()
8888
'ignore_contenttype' => [],
8989
'remove_link' => [],
9090
'ignore_listing' => false,
91+
'ignore_images' => false,
9192
];
9293
}
9394

templates/sitemap_xml.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{% else %}
2020
<priority>0.8</priority>
2121
{% endif %}
22-
{% for key,value in record.values|default %}
22+
{% for key,value in record.values|default if not ignore_images %}
2323
{% if record.fieldtype(key) == "image" and value != "" %}
2424
<image:image>
2525
<image:loc>{{ url('homepage')|trim('/', 'right') }}{{ value|image(config.get('general/thumbnails/default_image')|first, config.get('general/thumbnails/default_image')|last) }}</image:loc>

0 commit comments

Comments
 (0)