Skip to content

Commit 63bc3fb

Browse files
committed
Add sitemaps.
1 parent 94a29bf commit 63bc3fb

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

coltrane/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
DEFAULT_INSTALLED_APPS = [
4141
"django.contrib.humanize",
42+
"django.contrib.sitemaps",
4243
"django.contrib.staticfiles",
4344
"django_fastdev",
4445
"coltrane",

coltrane/sitemaps.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from django.contrib.sitemaps import Sitemap
2+
3+
from coltrane.retriever import get_content_paths
4+
5+
6+
class ContentSitemap(Sitemap):
7+
changefreq = "hourly"
8+
priority = 0.5
9+
10+
def items(self):
11+
return list(get_content_paths())
12+
13+
def location(self, obj):
14+
relative_url = str(obj)[7:-3]
15+
16+
if relative_url.endswith("/index"):
17+
relative_url = relative_url[:-6]
18+
19+
return relative_url

coltrane/urls.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from django.conf import settings
2+
from django.contrib.sitemaps.views import sitemap
23
from django.urls import include, path, re_path
34

5+
from coltrane.sitemaps import ContentSitemap
6+
47
from . import views
58

69

@@ -13,6 +16,14 @@
1316
path("__reload__/", include("django_browser_reload.urls")),
1417
]
1518

19+
sitemaps = {"content": ContentSitemap}
20+
1621
urlpatterns += [
22+
path(
23+
"sitemap.xml",
24+
sitemap,
25+
{"sitemaps": sitemaps},
26+
name="django.contrib.sitemaps.views.sitemap",
27+
),
1728
re_path(r"^(?P<slug>(\w|-|\/)*)", views.content, name="content"),
1829
]

0 commit comments

Comments
 (0)