From 501c91bd127eb2d15c16077df569cf3fe7412711 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 24 Oct 2017 21:14:17 +1100 Subject: [PATCH] Add a simple sitemap using django.contrib.sitemaps - there aren't a lot of pages to map so far so it's pretty basic ;) --- home/sitemaps.py | 12 ++++++++++++ lemoncurry/settings/base.py | 1 + lemoncurry/urls.py | 18 +++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 home/sitemaps.py diff --git a/home/sitemaps.py b/home/sitemaps.py new file mode 100644 index 0000000..a3c33b0 --- /dev/null +++ b/home/sitemaps.py @@ -0,0 +1,12 @@ +from django.contrib import sitemaps +from django.urls import reverse + + +class HomeSitemap(sitemaps.Sitemap): + changefreq = 'daily' + + def items(self): + return ('home:index',) + + def location(self, item): + return reverse(item) diff --git a/lemoncurry/settings/base.py b/lemoncurry/settings/base.py index d4901f5..21ab396 100644 --- a/lemoncurry/settings/base.py +++ b/lemoncurry/settings/base.py @@ -60,6 +60,7 @@ INSTALLED_APPS = [ 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', + 'django.contrib.sitemaps', 'django.contrib.messages', 'django.contrib.staticfiles', diff --git a/lemoncurry/urls.py b/lemoncurry/urls.py index 2a8662f..a9303b1 100644 --- a/lemoncurry/urls.py +++ b/lemoncurry/urls.py @@ -16,8 +16,20 @@ Including another URLconf from django.conf.urls import include, url from django.contrib import admin +import django.contrib.sitemaps.views as sitemap +from home.sitemaps import HomeSitemap + +sections = { + 'home': HomeSitemap, +} +maps = {'sitemaps': sections} + urlpatterns = [ - url(r'^', include('home.urls')), - url(r'^.well-known/', include('wellknowns.urls')), - url(r'^admin/', admin.site.urls), + url('', include('home.urls')), + url('^.well-known/', include('wellknowns.urls')), + url('^admin/', admin.site.urls), + + url(r'^sitemap\.xml$', sitemap.index, maps), + url(r'^sitemaps/(?P
.+)\.xml$', sitemap.sitemap, maps, + name='django.contrib.sitemaps.views.sitemap'), ]