Skip to content

Commit

Permalink
Added localized URLs for every page through the FoundationMetadataPag…
Browse files Browse the repository at this point in the history
…eMixin (#6849)

* Added localized URLs for every page through the FoundationMetadataPageMixin

* Cache sitemap

* Localized sitemaps
  • Loading branch information
KalobTaulien authored Jun 15, 2021
1 parent 600901e commit 8f0655d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions network-api/networkapi/sitemaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Solution came from Aleksi44 on Github:
# https://github.com/wagtail/wagtail/issues/6583#issuecomment-798960446
from django.contrib.sitemaps import views as sitemap_views
from wagtail.contrib.sitemaps.sitemap_generator import Sitemap


class CustomSitemap(Sitemap):

def items(self):
return (
self.get_wagtail_site()
.root_page
.localized # This is missing from sitemap_generator
.get_descendants(inclusive=True)
.live()
.public()
.order_by('path')
.specific())


def sitemap(request, **kwargs):
sitemaps = {'wagtail': CustomSitemap(request)}
return sitemap_views.sitemap(request, sitemaps, **kwargs)
6 changes: 4 additions & 2 deletions network-api/networkapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.http import HttpResponse
from django.views.decorators.cache import cache_page
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView
from django.views.generic.base import RedirectView
Expand All @@ -20,8 +21,8 @@

# from wagtail.core import urls as wagtail_urls
from .utility import watail_core_url_override as wagtail_urls
from .sitemaps import sitemap

from wagtail.contrib.sitemaps.views import sitemap
from wagtail_footnotes import urls as footnotes_urls
from networkapi.wagtailcustomization.image_url_tag_urls import urlpatterns as image_url_tag_urls
from networkapi.views import EnvVariablesView, review_app_help_view
Expand Down Expand Up @@ -60,7 +61,6 @@
re_path(r'^cms/', include(wagtailadmin_urls)),
re_path(r'^en/cms/', RedirectView.as_view(url='/cms/')),
re_path(r'^documents/', include(wagtaildocs_urls)),
re_path(r'^sitemap.xml$', sitemap),

# Sentry test url
path('sentry-debug', lambda r: 1 / 0) if settings.SENTRY_DSN and settings.DEBUG else None,
Expand Down Expand Up @@ -88,6 +88,8 @@

# wagtail-managed data
re_path(r'', include(wagtail_urls)),

path('sitemap.xml', cache_page(86400)(sitemap)),
)

if settings.USE_S3 is not True:
Expand Down

0 comments on commit 8f0655d

Please sign in to comment.