Table of Contents
Sitemaps & Drafts
Control sitemap output and drafts with Baseline defaults. You’ll set site.url, tweak per-page sitemap fields, use noindex, and see how draft: true behaves in dev vs build.
What you’ll build
- Pages that appear (or are excluded) in
sitemap.xml. - Per-page sitemap controls (
ignore,changefreq,priority,lastmod). - Draft pages that render in dev but are skipped in production builds.
Prerequisites
- Baseline installed and loaded (defaults keep sitemap on).
package.jsonwith"type": "module"and scripts:{ "type": "module", "scripts": { "dev": "npx @11ty/eleventy --serve", "build": "npx @11ty/eleventy" } }- Set
site.urlto your production URL for correct sitemap/canonical links (use localhost while testing).
1) Ensure Baseline sitemap is on (default)
eleventy.config.js with default options keeps the sitemap module enabled:
import baseline, { config as baselineConfig } from '@apleasantview/eleventy-plugin-baseline';
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
export default async function (eleventyConfig) {
// Sitemap is enabled by default
eleventyConfig.addPlugin(baseline());
}
export const config = baselineConfig;
2) Page with sitemap controls
Create src/content/pages/sitemap-demo.md:
---
title: 'Sitemap Demo'
description: 'Control sitemap entries.'
permalink: '/sitemap-demo/'
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.
3) Noindex (site-wide and per-page)
-
Site-wide: set
noindex: trueinsrc/_data/site.jsto skip the sitemap entirely. -
Per-page:
noindex: truein front matter is respected and excludes the page from the sitemap. Usesitemap: { ignore: true }if you want sitemap-only exclusion.sitemap: ignore: true eleventyExcludeFromCollections: truesitemap: { ignore: true }— removes it from the sitemap, page still renders.eleventyExcludeFromCollections: true— keeps it out of collections and thus out of the sitemap.
4) Drafts
Add draft: true in front matter:
draft: true
- Dev: drafts render in
npm run dev. - Build: when
ELEVENTY_RUN_MODE=build, drafts are skipped. - Baseline registers a drafts preprocessor (guarded so it won’t double-register); your own preprocessor wins if you add one.
5) Run and inspect
npx rimraf dist/ && npm run dev
- Open pages normally.
- Check
dist/sitemap.xmlwhile dev runs (sitemap is emitted and includes drafts). - Draft pages render in dev and show up in the dev sitemap; they are excluded from the sitemap when you build for production (
ELEVENTY_RUN_MODE=build).
6) Production build
npx rimraf dist/ && npm run build
Then inspect dist/sitemap.xml:
- Pages with
sitemap.ignore: trueare excluded. - Site-wide noindex: true (from
src/_data/site.js) excludes all sitemap entries. - Drafts (
draft: true) are excluded (becauseELEVENTY_RUN_MODE=buildis set by the build script).
7) Multilingual note
If multilingual is enabled, Baseline emits per-language sitemaps (e.g., /en/sitemap.xml, /nl/sitemap.xml) plus the root sitemap index. Per-page ignore/noindex/draft rules still apply per entry.
8) Next steps
- Keep
site.urlaccurate in production; usepathPrefixif deploying under a subpath. - Adjust
changefreq/prioritysparingly; search engines treat them as hints. - Use drafts for in-progress content; remember they return in dev.
- Set defaults in data files:
src/_data/sitemap.jsfor global sitemap defaults, or directory data (e.g.,posts.11tydata.js) to applysitemapsettings across a folder.
Previous: Debugging & Navigator
Next: Custom Social Previews