summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorFlorian Demmer <fdemmer@gmail.com>2020-07-29 10:33:20 +0200
committerCarlton Gibson <carlton@noumenal.es>2020-07-29 11:48:29 +0200
commit16218c20606d8cd89c5393970c83da04598a3e04 (patch)
treec1b968f621c4b948a80917c6fe3fcc93ec1dcad5 /docs
parent50e1ccbbea4c6f8e14a186149dd757483f0f0da5 (diff)
Fixed #27395 -- Added sitemap 'alternates' generation.
Updated the sitemap generator and default template to optionally include link elements with hreflang attribute to alternate language URLs.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/contrib/sitemaps.txt44
-rw-r--r--docs/releases/3.2.txt6
2 files changed, 49 insertions, 1 deletions
diff --git a/docs/ref/contrib/sitemaps.txt b/docs/ref/contrib/sitemaps.txt
index 8f89f6f899..936567411e 100644
--- a/docs/ref/contrib/sitemaps.txt
+++ b/docs/ref/contrib/sitemaps.txt
@@ -252,6 +252,40 @@ Note:
be generated using all of your :setting:`LANGUAGES`. The default is
``False``.
+ .. attribute:: Sitemap.languages
+
+ .. versionadded:: 3.2
+
+ **Optional.**
+
+ A :term:`sequence` of :term:`language codes<language code>` to use for
+ generating alternate links when :attr:`~Sitemap.i18n` is enabled.
+ Defaults to :setting:`LANGUAGES`.
+
+ .. attribute:: Sitemap.alternates
+
+ .. versionadded:: 3.2
+
+ **Optional.**
+
+ A boolean attribute. When used in conjunction with
+ :attr:`~Sitemap.i18n` generated URLs will each have a list of alternate
+ links pointing to other language versions using the `hreflang
+ attribute`_. The default is ``False``.
+
+ .. _hreflang attribute: https://support.google.com/webmasters/answer/189077
+
+ .. attribute:: Sitemap.x_default
+
+ .. versionadded:: 3.2
+
+ **Optional.**
+
+ A boolean attribute. When ``True`` the alternate links generated by
+ :attr:`~Sitemap.alternates` will contain a ``hreflang="x-default"``
+ fallback entry with a value of :setting:`LANGUAGE_CODE`. The default is
+ ``False``.
+
Shortcuts
=========
@@ -438,12 +472,22 @@ The variable ``urlset`` is a list of URLs that should appear in the
sitemap. Each URL exposes attributes as defined in the
:class:`~django.contrib.sitemaps.Sitemap` class:
+- ``alternates``
- ``changefreq``
- ``item``
- ``lastmod``
- ``location``
- ``priority``
+The ``alternates`` attribute is available when :attr:`~Sitemap.i18n` and
+:attr:`~Sitemap.alternates` are enabled. It is a list of other language
+versions, including the optional :attr:`~Sitemap.x_default` fallback, for each
+URL. Each alternate is a dictionary with ``location`` and ``lang_code`` keys.
+
+.. versionchanged:: 3.2
+
+ The ``alternates`` attribute was added.
+
The ``item`` attribute has been added for each URL to allow more flexible
customization of the templates, such as `Google news sitemaps`_. Assuming
Sitemap's :attr:`~Sitemap.items()` would return a list of items with
diff --git a/docs/releases/3.2.txt b/docs/releases/3.2.txt
index fe4b309cb5..10468ac655 100644
--- a/docs/releases/3.2.txt
+++ b/docs/releases/3.2.txt
@@ -125,7 +125,11 @@ Minor features
:mod:`django.contrib.sitemaps`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-* ...
+* The new :class:`~django.contrib.sitemaps.Sitemap` attributes
+ :attr:`~django.contrib.sitemaps.Sitemap.alternates`,
+ :attr:`~django.contrib.sitemaps.Sitemap.languages` and
+ :attr:`~django.contrib.sitemaps.Sitemap.x_default` allow
+ generating sitemap *alternates* to localized versions of your pages.
:mod:`django.contrib.sites`
~~~~~~~~~~~~~~~~~~~~~~~~~~~