Table of Contents
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. By the end you'll have per-page sitemap controls, a working noindex story, and a draft workflow that behaves differently in dev and build, the way you'd want.
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 production builds (and only from production builds).
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
- Baseline installed and loaded (defaults keep the sitemap on).
- Set
settings.urlto your production URL for correct sitemap and canonical links (use localhost while testing). package.jsonwith"type": "module"and thedev/buildscripts:{ "name": "simple-baseline-site", "type": "module", "scripts": { "start": "rimraf dist/ && npx @11ty/eleventy --serve", "build": "rimraf dist/ && cross-env ELEVENTY_ENV=production npx @11ty/eleventy" } }
1) Ensure the sitemap module is on (default)
Sitemap is on by default, so the eleventy.config.js from the previous tutorial is enough - no new options needed:
import baseline, { config as baselineConfig } from '@apleasantview/eleventy-plugin-baseline';
import settings from './src/_data/settings.js';
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
export default async function (eleventyConfig) {
eleventyConfig.addPlugin(
baseline(settings, {
head: {
titleSeparator: ' | ',
showGenerator: true
}
})
);
}
export const config = baselineConfig;
2) 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.
3) Noindex (site-wide and per-page)
Three knobs, in widening order of scope:
-
Site-wide: set
noindex: truein_data/settings.js. The whole sitemap is skipped. -
Per-page: set
noindex: truein front matter. The page renders arobotsnoindex tag and drops out of the sitemap. -
Sitemap-only: use
sitemap: { ignore: true }when the page should render normally but stay out of the sitemap.sitemap: ignore: true eleventyExcludeFromCollections: trueTwo flags, two scopes worth distinguishing:
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.
4) Drafts
Add draft: true in front matter:
draft: true
- In dev (
npm start): drafts render normally. - In build (
npm run build, which setsELEVENTY_ENV=production): drafts are skipped. - Baseline registers its own drafts preprocessor. If you already have one, yours wins; Baseline's is guarded against double-registration.
5) 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 as soon as you build for production, since
npm run buildsetsELEVENTY_ENV=production.
6) Production build
Change URL in .env to an absolute URL. On a deployed site that's your real production URL; for this exercise, any absolute URL (e.g. https://www.example.com/) works to verify the output. Then run:
npm run build
Then inspect dist/sitemap.xml. A few things should be missing:
- Pages with
sitemap.ignore: true. - Every entry, if site-wide
noindex: trueis set. - Anything marked
draft: true. - Reset
URLin.envto "http://localhost:8080/".
7) 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. - The sitemap module reference has the full option list.
Previous: Head and NoIndex
Next: Deployment URL Checks