# `SiteMaps.Plug`
[🔗](https://github.com/marcosgz/site_maps_ex/blob/v0.1.0/lib/site_maps/plug.ex#L1)

Serves generated sitemaps and the built-in XSL stylesheets.

    plug SiteMaps.Plug,
      sitemaps: &MyAppWeb.Sitemaps.for_conn/1,
      aliases: %{"/sitemap.xml" => "/sitemaps/sitemap.xml.gz"}

Works in an endpoint, a pipeline or behind a router `forward`. Requests that are not sitemap files
of the resolved module pass through untouched, so the plug can sit in front of the rest of the app.

## Options

  * `:sitemaps` - `{module, context}`, or a function receiving the conn and returning
    `{module, context}` or `nil` (pass through). Use a remote capture (`&Mod.fun/1`) when the plug
    is initialized at compile time. Required.
  * `:aliases` - map of request path to the path to serve, e.g. `%{"/sitemap.xml" => "/sitemap.xml.gz"}`.
    An `.xml` path aliased to an `.xml.gz` file is served uncompressed.
  * `:x_robots_tag` - `x-robots-tag` header (default `"noindex, follow"`, `nil` to omit)
  * `:cache_control` - `cache-control` header. For sitemaps it defaults to the configured
    `cache_control`, and the header is left out when both are `nil`. Stylesheets use this option
    when given, otherwise `"public, max-age=3600"`.
  * `:stylesheet_paths` - `{urlset_path, index_path}` serving the built-in stylesheets
    (default `{"/_sitemap-stylesheet.xsl", "/_sitemap-index-stylesheet.xsl"}`, `nil` to disable).
    Point `xsl_stylesheet_url`/`xsl_index_stylesheet_url` at them.

The request path must be inside the directory of the configured sitemap URL; the file key is the
percent-decoded path relative to it. Keys failing `SiteMaps.Adapter.validate_key/1` are rejected.
Only `.xml` and `.xml.gz` files are served. A `.xml` request for a missing file falls back to its
`.xml.gz` version, decompressed, when the sitemaps are gzipped.

Requests with an `if-modified-since` header at or after the file `last_modified` (compared in whole
seconds) get a `304 Not Modified`. `HEAD` requests get the `GET` headers without decompressing the
file; `content-length` is omitted when the file would be decompressed.

# `index_xsl`

```elixir
@spec index_xsl() :: String.t()
```

The built-in sitemap index XSL stylesheet.

# `urlset_xsl`

```elixir
@spec urlset_xsl() :: String.t()
```

The built-in urlset XSL stylesheet.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
