Skip to content
Permalink
Browse files

Adding a Sitemap

  • Loading branch information...
KalobTaulien committed Feb 8, 2019
1 parent d215c36 commit bc89fa7bf314f56302b4d8af3d0c89f6edbe72ec
Showing with 18 additions and 1 deletion.
  1. +14 −1 blog/models.py
  2. +2 −0 mysite/settings/base.py
  3. +2 −0 mysite/urls.py
@@ -33,12 +33,25 @@ def get_context(self, request, *args, **kwargs):
context["posts"] = BlogDetailPage.objects.live().public()
return context

@route(r'^latest/?$', name="latest_posts")
@route(r'^latest/$', name="latest_posts")
def latest_blog_posts_only_shows_last_5(self, request, *args, **kwargs):
context = self.get_context(request, *args, **kwargs)
context["posts"] = context["posts"][:1]
return render(request, "blog/latest_posts.html", context)

def get_sitemap_urls(self, request):
# Uncomment to have no sitemap for this page
# return []
sitemap = super().get_sitemap_urls(request)
sitemap.append(
{
"location": self.full_url + self.reverse_subpage("latest_posts"),
"lastmod": (self.last_published_at or self.latest_revision_created_at),
"priority": 0.9,
}
)
return sitemap


class BlogDetailPage(Page):
"""Blog detail page."""
@@ -37,6 +37,7 @@
'wagtail.contrib.redirects',
'wagtail.contrib.settings',
'wagtail.contrib.routable_page',
'wagtail.contrib.sitemaps',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
@@ -56,6 +57,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sitemaps',
]

MIDDLEWARE = [
@@ -5,6 +5,7 @@

from wagtail.admin import urls as wagtailadmin_urls
from wagtail.core import urls as wagtail_urls
from wagtail.contrib.sitemaps.views import sitemap
from wagtail.documents import urls as wagtaildocs_urls

from search import views as search_views
@@ -18,6 +19,7 @@

url(r'^search/$', search_views.search, name='search'),

url(r'^sitemap.xml$', sitemap),
# For anything not caught by a more specific rule above, hand over to
# Wagtail's page serving mechanism. This should be the last pattern in
# the list:

1 comment on commit bc89fa7

Please sign in to comment.
You can’t perform that action at this time.