# mod\_seo\_sitemap

Source: https://zotonic.com/docs/1292/mod_seo_sitemap

URI: https://zotonic.com/id/1292

Language: en



Creates a `sitemap.xml` file for your site, containing links to all publicly accessible pages.

mod\_seo\_sitemap creates a `sitemap.xml` file for which is used by the Google bot to index your site. By default, its generated sitemap.xml lists all pages of the categories text, event, location, collection and person in the system which are publicly viewable.

The sitemaps follow the specification at <https://www.sitemaps.org/protocol.html>

Maintaining the sitemap index
-----------------------------

The `seo_sitemap` model maintains an index of all pages (and their URLs) that are publicly readable.

There is a button in the Sitemap section of the SEO page to rebuild the sitemap index. This is needed if there are (big) changes in the access control affecting the publicly viewable pages or if languages are changed.

If a resource is edited then all URLs of that resource are automatically added to the sitemap index tables.

Structure of the sitemap
------------------------

The generated sitemap is an index file with links to urlset files.

The urlsets links are generated from a combination of two sources:

1. All resources and URLs in the sitemap index tables maintained by model `seo_sitemap`
2. Urlsets for by the `#seo_sitemap_index{}` notification.

The `#seo_sitemap_index{}` is a map notification where all modules can return 0 or more maps with information about their pages. The map should be like:

```erlang
#{
    source => <<"wherefrom">>,          % Unique code
    count => 1234,                      % Number of URLs
    size => 5000,                       % (optional) number of URLs per urlset
    lastmod => {{2021,5,12}, {0,0,0}}   % (optional) last modification date
}
```

The sitemap urlset is generated using the `#seo_sitemap_urlset{}` notification:

```erlang
#seo_sitemap_urlset, {
    source => <<"wherefrom">>,          % Unique code from the ``#seo_sitemap_index{}``
    offset => 1,                        % Offset for search, 1 based.
    limit => 50000                      % Number of URLs to be returned
}
```

This is a *first* notification and should return a list of maps. Each map contains a single URL:

```erlang
#{
    loc => <<"https://example.com/...", % The URL for the urlset
    lastmod => {{2021,5,12}, {0,0,0}}}, % (optional) last modification date
    priority => 0.5,                    % (optional) priority, between 0.0..1.0
    changefreq => <<"weekly">>          % (optional) change frequency, for recrawls
}
```

Creating a sitemap without using mod\_seo\_sitemap
--------------------------------------------------

If you have a site with mostly static URLS, it might be easier to create your own sitemap XML file. If you create a dispatch rule like this:

```erlang
{sitemap_xml, ["sitemap.xml"], controller_template, [{template, "mysitemap.tpl"}, {content_type, "text/xml"}]}
```

You will be able to write your own sitemap.xml file (in a mysitemap.tpl template) without using mod\_seo\_sitemap. This might be handy if you serve mostly static files.

Accepted Events
---------------

This module handles the following notifier callbacks:

- `observe_rsc_pivot_done`: Refresh sitemap metadata for the resource after pivoting changed its searchable fields.
- `observe_seo_sitemap_index`: Return the number of entries in the mod\_seo\_sitemap managed sitemaps using `m_seo_sitemap:count`.
- `observe_seo_sitemap_urlset`: Return the urlset belonging to the slice given using `m_seo_sitemap:slice`.

Delegate callbacks:

- `event/2` with `postback` messages: `sitemap_rebuild`.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1292?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1292?language=en>)
