SitemapBuilder (SitemapBuilder v0.1.0)

Copy Markdown View Source

Minimal, pipeline-friendly XML sitemap generator.

Build a sitemap by starting with new/1, adding entries via add/2 or add/3, and rendering to XML with generate/1.

Usage

SitemapBuilder.new("https://example.com")
|> SitemapBuilder.add(%SitemapBuilder{url: "/en", lastmod: ~D[2026-01-01]})
|> SitemapBuilder.add(posts, &%SitemapBuilder{url: "/posts/#{&1.slug}", lastmod: &1.updated_at})
|> SitemapBuilder.generate()

Each entry is a %SitemapBuilder{} struct with two required fields:

  • :url — path relative to the host (e.g. "/en/about")
  • :lastmod — accepts Date, DateTime, or an Ecto datetime tuple

Summary

Functions

Adds a pre-built %SitemapBuilder{} entry directly.

Adds a list of items or a single item, mapping each to a %SitemapBuilder{} entry via fun.

Renders the sitemap to an XML string.

Creates a new builder for the given host URL.

Functions

add(arg, sitemap)

Adds a pre-built %SitemapBuilder{} entry directly.

add(arg, list, fun)

Adds a list of items or a single item, mapping each to a %SitemapBuilder{} entry via fun.

generate(arg)

Renders the sitemap to an XML string.

new(host)

Creates a new builder for the given host URL.