Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a sitemap for the docs site.

Current docs have a higher priority than dev docs. Refs #18922.
  • Loading branch information...
commit 248bc06ed8904fff30c648737a97c9a01628686f 1 parent 0fd7006
@aaugustin aaugustin authored
View
2  django_docs/settings.py
@@ -8,6 +8,8 @@
CACHE_MIDDLEWARE_KEY_PREFIX = 'djangodocs'
INSTALLED_APPS = [
+ 'django.contrib.sitemaps',
+ 'django.contrib.sites',
'django.contrib.staticfiles',
'djangosecure',
View
9 django_docs/urls.py
@@ -1,5 +1,10 @@
from django.conf.urls import patterns, url, include
+from docs.sitemaps import DocsSitemap
+from docs.urls import urlpatterns as docs_urlpatterns
+
+sitemaps = {'docs': DocsSitemap}
+
urlpatterns = patterns('',
- url(r'', include('docs.urls')),
-)
+ url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
+) + docs_urlpatterns
View
26 docs/models.py
@@ -50,8 +50,11 @@ def human_version(self):
"""
Return a "human readable" version of the version.
"""
- return "Development trunk" if self.version == 'dev' \
- else "Django %s" % self.version
+ return "Development trunk" if self.is_dev else "Django %s" % self.version
+
+ @property
+ def is_dev(self):
+ return self.version == 'dev'
class Document(models.Model):
"""
@@ -66,9 +69,16 @@ def __unicode__(self):
@models.permalink
def get_absolute_url(self):
- kwargs = {
- 'lang': self.release.lang,
- 'version': self.release.version,
- 'url': self.path
- }
- return ('document-detail', [], kwargs)
+ if self.path:
+ kwargs = {
+ 'lang': self.release.lang,
+ 'version': self.release.version,
+ 'url': self.path,
+ }
+ return ('document-detail', [], kwargs)
+ else:
+ kwargs = {
+ 'lang': self.release.lang,
+ 'version': self.release.version,
+ }
+ return ('document-index', [], kwargs)
View
27 docs/sitemaps.py
@@ -0,0 +1,27 @@
+from django.contrib.sitemaps import Sitemap
+
+from .models import Document
+
+
+class DocsSitemap(Sitemap):
+
+ def items(self):
+ return (Document.objects
+ .order_by('release__lang', '-release__version', 'path')
+ .select_related('release'))
+
+ def changefreq(self, obj):
+ if obj.release.is_dev:
+ return 'daily'
+ elif obj.release.is_default:
+ return 'monthly'
+ else:
+ return 'yearly'
+
+ def priority(self, obj):
+ if obj.release.is_dev:
+ return 0.5
+ elif obj.release.is_default:
+ return 1
+ else:
+ return 0.1
Please sign in to comment.
Something went wrong with that request. Please try again.