mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 01:46:24 +01:00
24ef0e62e6
Fix code block indentation in tutorial.rst Prevent it from being displayed as a quote. Fix indentation in pages.rst Fix indentation in indexing.rst Fix indentation in searching.rst Fix indentation in backends.rst Fix indentation in renditions.rst Fix indentation in custom_image_model.rst Fix indentation in feature_detection.rst Fix indentation in image_serve_view.rst Fix indentation in custom_document_model.rst Fix indentation in i18n.rst Fix indentation in privacy.rst Fix indentation in page_editing_interface.rst Fix indentation in rich_text_internals.rst Fix indentation in extending_hallo.rst Fix indentation in configuration.rst Fix indentation in usage.rst Fix indentation in theory.rst Fix indentation in model_reference.rst Fix indentation in queryset_reference.rst Configure editors to indent .rst files with 2 spaces In order for the documentation to be styled correctly, the generator depends on indentation. Too much indentation can result in the content being wrapped in a quote block, which looks bad. Fix indentation in sitemaps.rst Fix indentation in frontendcache.rst Fix indentation in routablepage.rst Fix indentation in table_block.rst Fix routablepage.rst autodocs disppearing Fix indentation in table_block.rst Fix indentation in redirects.rst Fix indentation in table_documentation-modes.rst Fix indentation in browser_issues.rst Fix indentation in release_process.rst Fix indentation of release notes One more indent fix in the release notes Fix indentation warnings Fix warning about undefined label in docs Error during `make html`: wagtail/docs/releases/1.7.rst:25: WARNING: undefined label: jpeg_image_quality
125 lines
3.4 KiB
ReStructuredText
125 lines
3.4 KiB
ReStructuredText
.. _sitemap_generation:
|
|
|
|
Sitemap generator
|
|
=================
|
|
|
|
This document describes how to create XML sitemaps for your Wagtail website
|
|
using the ``wagtail.contrib.sitemaps`` 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.sitemaps.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 the Django documentation for in-depth information.
|
|
|
|
|
|
Basic configuration
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
You firstly need to add ``"django.contrib.sitemaps"`` to INSTALLED_APPS in your
|
|
Django settings file:
|
|
|
|
.. code-block:: python
|
|
|
|
INSTALLED_APPS = [
|
|
...
|
|
|
|
"django.contrib.sitemaps",
|
|
]
|
|
|
|
|
|
Then, in ``urls.py``, you need to add a link to the
|
|
``wagtail.contrib.sitemaps.views.sitemap`` view which generates the
|
|
sitemap:
|
|
|
|
.. code-block:: python
|
|
|
|
from wagtail.contrib.sitemaps.views import sitemap
|
|
|
|
urlpatterns = [
|
|
...
|
|
|
|
path('sitemap.xml', sitemap),
|
|
|
|
...
|
|
|
|
# Ensure that the 'sitemap' line appears above the default Wagtail page serving route
|
|
re_path(r'', include(wagtail_urls)),
|
|
]
|
|
|
|
|
|
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:
|
|
|
|
.. code-block:: xml
|
|
|
|
<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
|
|
|
|
<url>
|
|
<loc>http://mysite.com/about/</loc>
|
|
<lastmod>2015-09-26</lastmod>
|
|
</url>
|
|
|
|
|
|
If you change the site's port to ``443``, the ``https`` scheme will be used.
|
|
Find out more about :ref:`working with Sites<site-model-ref>`.
|
|
|
|
|
|
Customising
|
|
~~~~~~~~~~~
|
|
|
|
URLs
|
|
----
|
|
|
|
The ``Page`` class defines a ``get_sitemap_urls`` method which you can
|
|
override to customise sitemaps per ``Page`` instance. This method must accept
|
|
a request object and 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:
|
|
|
|
- **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**
|
|
|
|
You can add more but you will need to override the
|
|
``sitemap.xml`` template in order for them to be displayed in the sitemap.
|
|
|
|
|
|
Serving multiple sitemaps
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
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 the Django
|
|
documentation for further details.
|