Skip to content

Commit

Permalink
Updating Sitemap, according to @richardhinkamp's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bobdenotter committed Nov 7, 2014
1 parent 7b8bae7 commit eac7484
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ public function sitemap($xml = false)
$links = array(array('link' => $this->app['paths']['root'], 'title' => $this->app['config']->get('general/sitename')));
foreach ( $this->app['config']->get('contenttypes') as $contenttype ) {
if (!in_array($contenttype['slug'], $this->config['ignore_contenttype'])) {
$baseDepth = 0;
if (isset($contenttype['listing_template'])) {
$links[] = array( 'link' => $this->app['paths']['root'].$contenttype['slug'], 'title' => $contenttype['name'] );
$baseDepth = 1;
$links[] = array( 'link' => $this->app['paths']['root'].$contenttype['slug'], 'title' => $contenttype['name'], 'depth' => 1 );
}
$content = $this->app['storage']->getContent(
$contenttype['slug'],
array('limit' => 10000, 'order' => 'datepublish desc')
);
foreach ($content as $entry) {
$links[] = array('link' => $entry->link(), 'title' => $entry->getTitle(),
$links[] = array('link' => $entry->link(), 'title' => $entry->getTitle(), 'depth' => $baseDepth + 1,
'lastmod' => date( \DateTime::W3C, strtotime($entry->get('datechanged'))));
}
}
Expand Down
23 changes: 23 additions & 0 deletions assets/_sitemap_list.tiwg
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<ul>
{% set depth = 1 %}
{% for entry in entries %}
{% if entry.link is defined %}
{% if entry.depth is defined and entry.depth > depth %}
<ul>
{% endif %}
{% if entry.depth is defined and entry.depth < depth %}
</ul>
{% endif %}
<li><a href="{{ entry.link }}">{{ entry.title }}</a></li>

{% if entry.depth is defined %}
{% set depth = entry.depth %}
{% else %}
{% set depth = 1 %}
{% endif %}
{% endif %}
{% endfor %}
{% if depth > 1 %}
</ul>
{% endif %}
</ul>
1 change: 1 addition & 0 deletions assets/sitemap.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
{% endif %}
{% endfor %}
</ul>
{% include 'assets/_sitemap_list.twig' %}
</body>
</html>

0 comments on commit eac7484

Please sign in to comment.