Sitemap.xml - no extra access

#1

tl;dr

Enable access to the extra property of pages in the sitemap.xml template.

Full version

As the documentation says we get only permalink and date for a page. The sitemaps protocol defines a field called lastmod. This should be set to the date the page was last modified. Currently zola just set this field to the date of the post. This is in many cases not the same as the date.

Example: You post something in an blog. The publishing date is the date-field of this blog entry. 7 days later you update some details on this blogpost. The date will stay the same but lastmod should be updated.

I tried to do this by add an extra field into my content and adapted the sitemap.xml like this

  1 {% for page in pages %}
  2         <url>
  3             <loc>{{ page.permalink | safe }}</loc>
  4             {% if page.extra.lastmod %}
  5                 <lastmod>{{ page.extra.lastmod }}</lastmod>
  6             {% elif page.date %}
  7                 <lastmod>{{ page.date }}</lastmod>
  8             {% endif %}
  9         </url>
 10     {% endfor %}

but as we do not have access to the extra-context in this template this will not work.
So i suggest to enable access to the extra-content in this template.

#2

Good point, I’ll add that for the next version.
Sitemap changed significantly in the next branch though but it will be simple to add that.

1 Like
#3

I pushed it to the next branch if you want to give it a try

#4

Works nicely. The default sitemap.xml looks now also much cleaner. Thanks!