wagtail/docs/reference/contrib/sitemaps.rst

89 wiersze
2.6 KiB
ReStructuredText
Czysty Zwykły widok Historia

.. _sitemap_generation:
2015-05-14 14:27:14 +00:00
Sitemap generator
=================
2014-07-01 09:14:34 +00:00
This document describes how to create XML sitemaps for your Wagtail website using the ``wagtail.contrib.wagtailsitemaps`` module.
Basic configuration
~~~~~~~~~~~~~~~~~~~
You firstly need to add ``"wagtail.contrib.wagtailsitemaps"`` to INSTALLED_APPS in your Django settings file:
.. code-block:: python
INSTALLED_APPS = [
...
"wagtail.contrib.wagtailsitemaps",
]
2015-04-19 09:53:34 +00:00
Then, in ``urls.py``, you need to add a link to the ``wagtail.contrib.wagtailsitemaps.views.sitemap`` view which generates the sitemap:
2014-07-01 09:14:34 +00:00
.. code-block:: python
from wagtail.contrib.wagtailsitemaps.views import sitemap
2015-04-02 12:09:02 +00:00
urlpatterns = [
2014-07-01 09:14:34 +00:00
...
url('^sitemap\.xml$', sitemap),
2015-04-02 12:09:02 +00:00
]
2014-07-01 09:14:34 +00:00
You should now be able to browse to ``/sitemap.xml`` and see the sitemap working. By default, all published pages in your website will be added to the site map.
2014-07-01 09:14:34 +00:00
2015-09-26 13:41:52 +00:00
Setting the hostname
~~~~~~~~~~~~~~~~~~~~
By default, the sitemap uses the hostname defined in the Wagtail Admin's ``Sites`` area. If your
default site is called ``localhost``, then URLs in the sitemap will look like:
.. code-block:: xml
2015-09-26 13:41:52 +00:00
<url>
<loc>http://localhost/about/</loc>
<lastmod>2015-09-26</lastmod>
</url>
For tools like Google Search Tools to properly index your site, you need to set a valid, crawlable hostname. If you change the site's hostname from ``localhost`` to ``mysite.com``, ``sitemap.xml``
will contain the correct URLs:
.. code-block:: xml
2015-09-26 13:41:52 +00:00
<url>
<loc>http://mysite.com/about/</loc>
<lastmod>2015-09-26</lastmod>
</url>
2016-10-01 19:04:46 +00:00
Find out more about :ref:`working with Sites<site-model-ref>`.
2015-09-26 13:41:52 +00:00
2014-07-01 09:14:34 +00:00
Customising
~~~~~~~~~~~
URLs
----
The ``Page`` class defines a ``get_sitemap_urls`` method which you can override to customise sitemaps per ``Page`` instance. This method must return a list of dictionaries, one dictionary per URL entry in the sitemap. You can exclude pages from the sitemap by returning an empty list.
2014-07-01 09:14:34 +00:00
Each dictionary can contain the following:
- **location** (required) - This is the full URL path to add into the sitemap.
- **lastmod** - A python date or datetime set to when the page was last modified.
- **changefreq**
- **priority**
2014-07-02 12:45:43 +00:00
You can add more but you will need to override the ``wagtailsitemaps/sitemap.xml`` template in order for them to be displayed in the sitemap.
2014-07-01 09:14:34 +00:00
Cache
-----
2014-07-02 12:01:49 +00:00
By default, sitemaps are cached for 100 minutes. You can change this by setting ``WAGTAILSITEMAPS_CACHE_TIMEOUT`` in your Django settings to the number of seconds you would like the cache to last for.