12. Sitemap for search engines
Date: 2026-11-26
Status
Accepted and implemented: the build writes sitemap.xml at the output root.
Unit tests sitemap_lists_index_pages_and_skips_not_found and
urls_are_sorted_and_base_has_no_double_slash in src/generator/sitemap.rs,
and the integration test the_build_emits_a_sitemap in
tests/example_site.rs cover it.
Context
listsome sites are static files. Search engines need a way to discover the
pages. Without a sitemap, they crawl what they can find by following links, and
they miss anything that is not reachable from a top-level page. Mature static
site generators emit a sitemap.xml for this reason; the old site being
migrated already had one, and losing it is a regression.
The hard problem in sitemap generation is not the XML (a simple document) but
keeping the sitemap in sync with the pages the generator actually emits. Every
collection and feature that adds pages (projects/, notes/,
tools/, tool-tag pages, tag pages, category pages, pagination, the about page
once the author config carries one, and any future page type) must be reflected
in the sitemap. Reconstructing URLs by iterating those collections from the
generator duplicates the URL shapes and risks drift whenever a scheme changes.
listsome also has a principle of build determinism (the webmention ledger work
made sent.json byte-stable across rebuilds). A sitemap that stamps <lastmod>
from file metadata or build time breaks that principle: every rebuild would
produce a different XML, which is noise for diff-based deploys and semantically
wrong because the content did not actually change.
Decision
Emit sitemap.xml from the generated output tree. After every page is written,
the generator walks output_dir recursively, collects every index.html, and
turns each into one canonical <url><loc> under site.url. The not-found page
(404.html) is excluded.
Two rules make this correct and stable:
- Only walk, do not reconstruct. A file’s presence in
output/is the source of truth for “the page exists,” and the file’s location is the source of truth for “the page’s URL.” The URL mapping is a one-line transformation (/foo/index.html→/foo/,/index.html→/) and needs no knowledge of the content model. - No
<lastmod>. Skip it. The sitemap is a discovery document, not a freshness document; the host’s response headers already carry freshness, and search engines accept loc-only entries. This keeps the file byte-for-byte deterministic across rebuilds, aligned with the ledger principle.
The generator sorts and dedupes URLs before writing so the same input produces the same bytes regardless of filesystem read order.
Consequences
- A sitemap is emitted for every site automatically. Nothing to configure.
- Search engines can index the whole site by reading one XML document.
- The sitemap can never drift from the actual output. A future page type that
writes an
index.htmlunder the output tree shows up in the sitemap with no additional wiring. <lastmod>is missing, which is technically permitted by sitemaps.org 0.9. If freshness ever matters for this corpus, the right place to fix it is in the page metadata (frontmatterupdated:), not in filesystem modification times, so the determinism guarantee survives.- Non-page artifacts (
rss.xml,notes.xml,404.html,.webmentions/) are deliberately excluded. The build’sindex.htmlfiles are the only inputs. - A build now produces one extra file at the root. Harmless to diff-based deploys.