Eleventy Plugin Baseline

A magic carpet ride

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.json with "type": "module" and scripts:
    {
    	"type": "module",
    	"scripts": {
    		"dev": "npx @11ty/eleventy --serve",
    		"build": "npx @11ty/eleventy"
    	}
    }
  • Set site.url to 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: true in src/_data/site.js to skip the sitemap entirely.

  • Per-page: noindex: true in front matter is respected and excludes the page from the sitemap. Use sitemap: { ignore: true } if you want sitemap-only exclusion.

    sitemap:
      ignore: true
    eleventyExcludeFromCollections: true
    • sitemap: { 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.xml while 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: true are excluded.
  • Site-wide noindex: true (from src/_data/site.js) excludes all sitemap entries.
  • Drafts (draft: true) are excluded (because ELEVENTY_RUN_MODE=build is 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.url accurate in production; use pathPrefix if deploying under a subpath.
  • Adjust changefreq/priority sparingly; 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.js for global sitemap defaults, or directory data (e.g., posts.11tydata.js) to apply sitemap settings across a folder.