Skip to content

Commit

Permalink
feat: Add sitemap.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Dec 11, 2023
1 parent 80ccb35 commit 0a5bfb1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sitemaps",
"django.contrib.humanize",
"data_registry",
"markdownx",
Expand Down
32 changes: 32 additions & 0 deletions data_registry/sitemaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.contrib.sitemaps import Sitemap
from django.urls import reverse

from data_registry import models


class StaticViewSitemap(Sitemap):
i18n = True
alternates = True
protocol = "https"

def items(self):
return ["index", "search"]

def location(self, item):
return reverse(item)


class CollectionSitemap(Sitemap):
i18n = True
alternates = True
protocol = "https"

# See data_registry.util.collection_queryset().
def items(self):
return models.Collection.objects.visible()

def location(self, item):
return reverse("detail", kwargs={"id": item.pk})

def lastmod(self, obj):
return obj.modified
13 changes: 10 additions & 3 deletions data_registry/urls.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from django.contrib.sitemaps.views import sitemap
from django.urls import path

from data_registry import i18n, views
from data_registry import i18n, sitemaps, views

maps = {
"static": sitemaps.StaticViewSitemap,
"detail": sitemaps.CollectionSitemap,
}

urlpatterns = [
path("", views.index, name="index"),
path("search/", views.search, name="search"),
path("publication/<int:id>", views.detail, name="detail"),
path("publication/<int:id>/download", views.download_export, name="download"),
# https://code.djangoproject.com/ticket/26556
path("i18n/setlang/", i18n.set_language, name="set-language"),
# Uncomment after re-integrating Spoonbill.
# path("excel-data/<int:job_id>/<str:job_range>", views.excel_data, name="excel-data"),
# path("excel-data/<int:job_id>", views.excel_data, name="all-excel-data"),
# https://code.djangoproject.com/ticket/26556
path("i18n/setlang/", i18n.set_language, name="set-language"),
path("sitemap.xml", sitemap, {"sitemaps": maps}, name="django.contrib.sitemaps.views.sitemap"),
]

0 comments on commit 0a5bfb1

Please sign in to comment.