Add multi-level nesting support to sitemap.xml

Fixes #1481.
This commit is contained in:
Waylan Limberg
2018-05-09 10:58:23 -04:00
parent e5c2459fdf
commit 7e06ca68d1
2 changed files with 21 additions and 17 deletions

View File

@@ -88,6 +88,10 @@ authors should review how [search and themes] interact.
* Update links to Python-Markdown library (#1360).
* Document how to generate manpages for MkDocs commands (#686).
## Version 0.17.4
* Bugfix: Add multi-level nesting support to sitemap.xml (#1482).
## Version 0.17.3 (2018-03-07)
* Bugfix: Set dependency `tornado>=4.1,<5.0` due to changes in 5.0 (#1428).

View File

@@ -1,20 +1,20 @@
{%- macro nav_item(item) -%}
{%- if item.children -%}
{%- for child in item.children -%}
{{ nav_item(child) }}
{%- endfor -%}
{%- else %}
<url>
<loc>{% if item.canonical_url %}{{ item.canonical_url }}{% else %}{{ item.abs_url }}{% endif %}</loc>
{% if item.update_date %}<lastmod>{{item.update_date}}</lastmod>{% endif %}
<changefreq>daily</changefreq>
</url>
{%- endif -%}
{%- endmacro -%}
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for nav_item in nav %}
{% if nav_item.children %}
{% for nav_item in nav_item.children %}
<url>
<loc>{{ config.site_url }}{{ nav_item.abs_url }}</loc>
{% if nav_item.update_date %}<lastmod>{{nav_item.update_date}}</lastmod>{% endif %}
<changefreq>daily</changefreq>
</url>
{% endfor %}
{% else %}
<url>
<loc>{{ config.site_url }}{{ nav_item.abs_url }}</loc>
{% if nav_item.update_date %}<lastmod>{{nav_item.update_date}}</lastmod>{% endif %}
<changefreq>daily</changefreq>
</url>
{% endif %}
{% endfor %}
{%- for item in nav -%}
{{ nav_item(item) }}
{%- endfor %}
</urlset>