Main sitemap generator for PhoenixKit.
Generates a <sitemapindex> at /sitemap.xml referencing per-module
sitemap files at /sitemaps/sitemap-{source}.xml.
Architecture
/sitemap.xml- Always a<sitemapindex>referencing per-module files/sitemaps/sitemap-static.xml- Static pages/sitemaps/sitemap-routes.xml- Router discovery/sitemaps/sitemap-publishing.xml- Publishing posts (or per-blog files)/sitemaps/sitemap-shop.xml- Shop products (auto-split at 50k)/sitemaps/sitemap-entities.xml- Entities (or per-type files)
HTML sitemaps are rendered by PhoenixKit.Modules.Sitemap.HtmlGenerator.
Usage
# Generate all sitemaps (index + per-module files)
{:ok, result} = Generator.generate_all(base_url: "https://example.com")
# Generate HTML sitemap (collects from all sources)
{:ok, html} = Generator.generate_html(base_url: "https://example.com")
# Backward compatible: generate_xml returns the sitemapindex
{:ok, xml} = Generator.generate_xml(base_url: "https://example.com")
Summary
Functions
Collects URL entries from all enabled sources.
Generates all sitemaps: per-module files and the sitemapindex.
Generates HTML sitemap from all enabled sources.
Builds <sitemapindex> XML from a list of %SitemapFile{} structs.
Generates sitemap file(s) for a single source module.
Generates XML sitemap. Returns the sitemapindex XML.
Gets a specific sitemap part by index (1-based).
Invalidates cache AND triggers async regeneration.
Invalidates all cached sitemaps.
Functions
@spec collect_all_entries( keyword(), [module()] ) :: [PhoenixKit.Modules.Sitemap.UrlEntry.t()]
Collects URL entries from all enabled sources.
When the Languages module is enabled, automatically collects entries for all enabled languages and adds hreflang alternate links.
Generates all sitemaps: per-module files and the sitemapindex.
Options
:base_url- Base URL for building full URLs (required):xsl_style- XSL stylesheet style: "table" or "minimal" (default: "table"):xsl_enabled- Enable XSL stylesheet reference (default: true)
Returns
{:ok, %{
index_xml: "<?xml ...sitemapindex...",
modules: [
%{filename: "sitemap-static", url_count: 3, lastmod: ~U[...]}
],
total_urls: 150
}}
Generates HTML sitemap from all enabled sources.
Delegates to PhoenixKit.Modules.Sitemap.HtmlGenerator.
Options
:base_url- Base URL for building full URLs (required):style- Display style: "hierarchical", "grouped", or "flat" (default: "hierarchical"):cache- Enable/disable caching (default: true):title- Page title (default: "Sitemap")
@spec generate_index( [PhoenixKit.Modules.Sitemap.SitemapFile.t()], String.t(), String.t(), boolean() ) :: String.t()
Builds <sitemapindex> XML from a list of %SitemapFile{} structs.
@spec generate_module( module(), keyword() ) :: [PhoenixKit.Modules.Sitemap.SitemapFile.t()]
Generates sitemap file(s) for a single source module.
Returns a list of %SitemapFile{} structs (one per file generated).
Empty sources produce no files and return [].
Generates XML sitemap. Returns the sitemapindex XML.
Delegates to generate_all/1 and returns the index XML for backward compatibility.
Gets a specific sitemap part by index (1-based).
Legacy function for backward compatibility with old numbered sitemap parts.
@spec invalidate_and_regenerate() :: {:ok, Oban.Job.t()} | {:error, term()}
Invalidates cache AND triggers async regeneration.
@spec invalidate_cache() :: :ok
Invalidates all cached sitemaps.