From 3fe0c69332299dc1d518cc3a4f84bf435deecc1d Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 28 Jun 2011 10:16:34 +0000 Subject: Fixed #10907, #14190 and #15829 -- Pass item to sitemaps template to allow further customization like Google News enabled sitemaps. Thanks, manfre and lakinwecker. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16474 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/ref/contrib/sitemaps.txt | 71 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 7 deletions(-) (limited to 'docs') diff --git a/docs/ref/contrib/sitemaps.txt b/docs/ref/contrib/sitemaps.txt index d7dcc2e512..6d8fe61f35 100644 --- a/docs/ref/contrib/sitemaps.txt +++ b/docs/ref/contrib/sitemaps.txt @@ -284,10 +284,10 @@ Here's what the relevant URLconf lines would look like for the example above:: (r'^sitemap-(?P
.+)\.xml$', 'sitemap', {'sitemaps': sitemaps}), ) -This will automatically generate a :file:`sitemap.xml` file that references both -:file:`sitemap-flatpages.xml` and :file:`sitemap-blog.xml`. The -:class:`~django.contrib.sitemaps.Sitemap` classes and the :data:`sitemaps` dict -don't change at all. +This will automatically generate a :file:`sitemap.xml` file that references +both :file:`sitemap-flatpages.xml` and :file:`sitemap-blog.xml`. The +:class:`~django.contrib.sitemaps.Sitemap` classes and the :data:`sitemaps` +dict don't change at all. You should create an index file if one of your sitemaps has more than 50,000 URLs. In this case, Django will automatically paginate the sitemap, and the @@ -298,9 +298,9 @@ index will reflect that. Template customization ====================== -If you wish to use a different template for each sitemap or sitemap index available on your site, -you may specify it by passing a `template_name` parameter to the `sitemap` and `index` views via -the URLconf:: +If you wish to use a different template for each sitemap or sitemap index +available on your site, you may specify it by passing a ``template_name`` +parameter to the ``sitemap`` and ``index`` views via the URLconf:: urlpatterns = patterns('django.contrib.sitemaps.views', (r'^custom-sitemap\.xml$', 'index', { @@ -313,6 +313,63 @@ the URLconf:: }), ) +Context variables +------------------ + +When customizing the templates for the :func:`~django.contrib.sitemaps.views.index` +and ~:func:`django.contrib.sitemaps.views.sitemaps` views, you can rely on the +following context variables. + +Index +----- + +The variable :data:`sitemaps` is a list of absolute URLs to each of the sitemaps. + +Sitemap +------- + +The variable :data:`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: + + - ``changefreq`` + - ``item`` + - ``lastmod`` + - ``location`` + - ``priority`` + +.. versionadded:: 1.4 + +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 +``publication_data`` and a ``tags`` field something like this would +generate a Google News compatible sitemap: + +.. code-block:: xml+django + + + + {% spaceless %} + {% for url in urlset %} + + {{ url.location }} + {% if url.lastmod %}{{ url.lastmod|date:"Y-m-d" }}{% endif %} + {% if url.changefreq %}{{ url.changefreq }}{% endif %} + {% if url.priority %}{{ url.priority }}{% endif %} + + {% if url.item.publication_date %}{{ url.item.publication_date|date:"Y-m-d" }}{% endif %} + {% if url.item.tags %}{{ url.item.tags }}{% endif %} + + + {% endfor %} + {% endspaceless %} + + +.. _`Google news sitemaps`: http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=74288 + Pinging Google ============== -- cgit v1.3