Templates NEW Sitemap

Usage example for /11ty/eleventy-plugin-rss:

---
permalink: /sitemap.xml
layout: false
eleventyExcludeFromCollections: true
---
{% include 'blades/sitemap.xml.njk' %}

How it works

/anyblades/blades/refs/heads/main/_includes/blades/sitemap.xml.njk :

version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
  {%- for page in collections.all %}
    {% if page.data.permalink != false %}
      <url>
        <loc>{{ site.base }}{{ page.url }}</loc>
        <lastmod>{{ page.date | date }}</lastmod>
      </url>
    {% endif %}
  {%- endfor %}
</urlset>

Render from a standalone route/template that outputs application/xml:

{% include 'blades/sitemap.xml.twig' %}

date('c') emits an ISO-8601 lastmod, which is what the sitemap spec expects.


How it works

/anyblades/blades/refs/heads/main/_includes/blades/sitemap.xml.twig :

<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
  {%- for page in collections.all %}
    {% if page.data.permalink != false %}
      <url>
        <loc>{{ site.base }}{{ page.url }}</loc>
        <lastmod>{{ page.date|date('c') }}</lastmod>
      </url>
    {% endif %}
  {%- endfor %}
</urlset>