GuideHow-to recipes
Add a sitemap
Generate sitemap.xml from collections.all with a Liquid template, leave pages out, and point robots.txt to it.
A sitemap is a template over collections.all, the list of every page of the site. sitemap.xml.liquid in the content
folder is rendered like a page and written to sitemap.xml. Templates that are not pages, such as the sitemap itself
or a feed, are not in the collections.
Set the site URLLink to this heading
The URLs of a sitemap are absolute. Set site.url, which the absolute_url filter prefixes:
site:
url: https://example.com
Write the sitemapLink to this heading
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{%- assign pages = collections.all | where_exp: "p", "p.data.sitemap != false" %}
{%- for p in pages %}
<url>
<loc>{{ p.data.url | replace: 'index.html', '' | absolute_url }}</loc>
<lastmod>{{ p.data.page.date | date_to_xmlschema }}</lastmod>
</url>
{%- endfor %}
</urlset>
Save it as _content/sitemap.xml.liquid. The build writes _site/sitemap.xml:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/</loc>
<lastmod>2026-10-23T16:32:02+00:00</lastmod>
</url>
<url>
<loc>https://example.com/docs/a/</loc>
<lastmod>2026-10-23T16:32:02+00:00</lastmod>
</url>
</urlset>
urlis the output path of a page (/docs/a/index.html); removingindex.htmlgives the folder URL.page.dateis the modification time of the source file. In a CI checkout every file has the time of the checkout: Add last modified time sets it from Git instead. Usep.data.dateto list the front matter date of the pages that have one.- The
liquidstep encodes the outputs of an XML file for XML: a&in a URL is written&, and the+of a time offset stays as it is.
Leave pages outLink to this heading
The where_exp filter keeps the pages for which the expression is true. A page that should not be listed, such as a
404 page or a draft, sets sitemap: false in its front matter:
---
permalink: /404.html
sitemap: false
---
<h1>Not found</h1>
A data file of a folder can set it for every page of the folder:
sitemap: false
Point robots.txt to itLink to this heading
robots.txt.liquid is rendered and written to robots.txt:
User-agent: *
Allow: /
Sitemap: {{ '/sitemap.xml' | absolute_url }}
Multilingual sitesLink to this heading
On a site with site.locales and the localize step, the locale_pages filter lists every page of every locale,
fallback copies included, as { locale, lang, url, fallback, data }. See
Internationalization.