Sayfa.Sitemap (Sayfa v0.5.0)

Copy Markdown View Source

Generates XML sitemaps for search engine discovery.

Produces a standard sitemap.xml with <urlset>, <url>, <loc>, and optional <lastmod> elements.

Examples

urls = [%{loc: "/articles/hello/", lastmod: ~D[2024-01-15]}, %{loc: "/about/", lastmod: nil}]
config = %{base_url: "https://example.com"}
xml = Sayfa.Sitemap.generate(urls, config)

Summary

Functions

Generates a sitemap XML string.

Functions

generate(urls, config)

@spec generate([%{loc: String.t(), lastmod: Date.t() | nil}], map()) :: String.t()

Generates a sitemap XML string.

Takes a list of URL maps and site config. Each URL map should have:

  • :loc — the path (e.g., "/articles/hello/")
  • :lastmod — a Date or nil

Examples

iex> urls = [%{loc: "/articles/hello/", lastmod: ~D[2024-01-15]}, %{loc: "/about/", lastmod: nil}]
iex> config = %{base_url: "https://example.com"}
iex> xml = Sayfa.Sitemap.generate(urls, config)
iex> xml =~ "https://example.com/articles/hello/"
true
iex> xml =~ "<lastmod>2024-01-15</lastmod>"
true
iex> xml =~ "https://example.com/about/"
true