kopia lustrzana https://github.com/wagtail/wagtail
Update documentation related to the sitemaps
Since we now use regular Django sitemaps we can mostly just refer to the Django documentation Co-authored with @mikedingjanpull/3554/head
rodzic
2f79e42948
commit
c6c2868c58
|
@ -3,24 +3,42 @@
|
|||
Sitemap generator
|
||||
=================
|
||||
|
||||
This document describes how to create XML sitemaps for your Wagtail website using the ``wagtail.contrib.wagtailsitemaps`` module.
|
||||
This document describes how to create XML sitemaps for your Wagtail website
|
||||
using the ``wagtail.contrib.wagtailsitemaps`` module.
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
As of Wagtail 1.10 the Django contrib sitemap app is used to generate
|
||||
sitemaps. However since Wagtail requires the Site instance to be available
|
||||
during the sitemap generation you will have to use the views from the
|
||||
``wagtail.contrib.wagtailsitemaps.views`` module instead of the views
|
||||
provided by Django (``django.contrib.sitemaps.views``).
|
||||
|
||||
The usage of these views is otherwise identical, which means that
|
||||
customisation and caching of the sitemaps are done using the default Django
|
||||
patterns. See for in-depth information the Django documentation.
|
||||
|
||||
|
||||
Basic configuration
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
You firstly need to add ``"wagtail.contrib.wagtailsitemaps"`` to INSTALLED_APPS in your Django settings file:
|
||||
|
||||
You firstly need to add ``"django.contrib.sitemaps"`` to INSTALLED_APPS in your
|
||||
Django settings file:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
INSTALLED_APPS = [
|
||||
...
|
||||
|
||||
"wagtail.contrib.wagtailsitemaps",
|
||||
"django.contrib.sitemaps",
|
||||
]
|
||||
|
||||
|
||||
Then, in ``urls.py``, you need to add a link to the ``wagtail.contrib.wagtailsitemaps.views.sitemap`` view which generates the sitemap:
|
||||
Then, in ``urls.py``, you need to add a link to the
|
||||
``wagtail.contrib.wagtailsitemaps.views.sitemap`` view which generates the
|
||||
sitemap:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -38,14 +56,17 @@ Then, in ``urls.py``, you need to add a link to the ``wagtail.contrib.wagtailsit
|
|||
]
|
||||
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
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:
|
||||
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
|
||||
|
||||
|
@ -55,8 +76,9 @@ default site is called ``localhost``, then URLs in the sitemap will look like:
|
|||
</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:
|
||||
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
|
||||
|
||||
|
@ -75,7 +97,10 @@ 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.
|
||||
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.
|
||||
|
||||
Each dictionary can contain the following:
|
||||
|
||||
|
@ -84,10 +109,14 @@ Each dictionary can contain the following:
|
|||
- **changefreq**
|
||||
- **priority**
|
||||
|
||||
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.
|
||||
You can add more but you will need to override the
|
||||
``sitemap.xml`` template in order for them to be displayed in the sitemap.
|
||||
|
||||
|
||||
Cache
|
||||
-----
|
||||
Serving multiple sitemaps
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
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.
|
||||
If you want to support the sitemap indexes from Django then you will need to
|
||||
use the index view from ``wagtail.contrib.sitemaps.views`` instead of the
|
||||
index view from ``django.contrib.sitemaps.views``. Please see for further
|
||||
details the Django documentation.
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.contrib.sites.shortcuts import get_current_site
|
||||
from django.core.cache import cache
|
||||
from django.test import RequestFactory, TestCase
|
||||
|
||||
from wagtail.tests.testapp.models import EventIndex, SimplePage
|
||||
|
|
Ładowanie…
Reference in New Issue