Sitemaps and drafts
Control which pages end up in your sitemap, and let work-in-progress pages live alongside published ones without leaking into production. Those are separate switches, and knowing which one you want is most of the work.
Two terms used below:
- Sitemap index. The root
sitemap.xmlthat lists per-language sitemaps when multilingual is on. - Drafts preprocessor. The build-time hook Baseline registers to drop
draft: truepages from any build (and only from builds; serving and watching keep them).
What you will build
- Pages that appear in
sitemap.xml, and pages that don't. - Per-page sitemap controls:
ignore,changefreq,priority,lastmod. - Draft pages that render in dev and quietly disappear in production.
Prerequisites
settings.url set, so the <loc> entries come out absolute. The sitemap module is on by default, so there are no new options to add.
Page with sitemap controls
Create src/content/pages/sitemap-demo.md:
---
title: 'Sitemap Demo'
slug: 'sitemap-demo'
description: 'Control sitemap entries.'
layout: 'layouts/base.njk'
sitemap:
changefreq: 'weekly'
priority: 0.7
lastmod: 2024-01-01
---
This page stays in the sitemap with custom frequency, priority, and lastmod.
changefreq, priority, and lastmod are hints, not directives. Search engines treat them as suggestions, so adjust sparingly.
Keeping a page out
The three noindex knobs are covered on the previous page, head and noindex: site-wide, per-page, and sitemap-only. The one that belongs here is the fourth, because it is a sitemap mechanic rather than a robots one:
sitemap:
ignore: true
eleventyExcludeFromCollections: true
sitemap: { ignore: true }removes the page from the sitemap; the page still renders.eleventyExcludeFromCollections: truekeeps the page out of collections, and because the sitemap reads from collections, out of the sitemap too.
The second is the blunter instrument. Reach for it when the page should not appear in any listing, not just this one.
Drafts
Add draft: true in front matter:
draft: true
- In dev (
npm start): drafts render normally. - In any build: drafts are skipped. The switch is Eleventy's own
ELEVENTY_RUN_MODE, which isbuildfor anything that is not serving or watching, so a bareeleventyrun with no--serveor--watchdrops them too. This is not theELEVENTY_ENVyourbuildscript sets; that one governs CSS minification and the navigator. - Baseline registers its own drafts preprocessor. If you already have one, yours wins; Baseline's is guarded against double-registration.
Run and inspect
npm start
- Open pages normally.
- Check
dist/sitemap.xmlwhile dev runs. It's emitted, drafts included. - Draft pages render in dev and show up in the dev sitemap. They drop out the moment you build rather than serve.
Production build
npm run build
Then inspect dist/sitemap.xml. Three things should be missing:
- Pages with
sitemap.ignore: true. - Every entry, if site-wide
noindex: trueis set. - Anything marked
draft: true.
The <loc> entries are absolute, anchored to settings.url. If they come out relative, the origin never reached the build: deployment checks covers that.
Multilingual note
When multilingual is on, Baseline emits a per-language sitemap (/en/sitemap.xml, /nl/sitemap.xml, and so on) plus a sitemap index at the root. The per-page ignore, noindex, and draft rules apply to each entry just the same.
Next steps
- Keep
settings.urlaccurate in production, and setpathPrefixif you deploy under a subpath. - Use drafts freely for in-progress content. Just remember they reappear in dev.
- Set defaults at the data layer:
_data/sitemap.jsfor site-wide sitemap defaults, or directory data (e.g.posts.11tydata.js) to applysitemapsettings across a folder.
See also
- Sitemap module - the full option list.
- Deploy under a subpath - what
pathPrefixdoes to sitemap URLs.