Skip to content

Commit 18e53d2

Browse files
committed
feat: add sitemap framework
1 parent d0c1ee2 commit 18e53d2

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

config/settings/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"django.contrib.sessions",
4343
"django.contrib.messages",
4444
"django.contrib.staticfiles",
45+
"django.contrib.sitemaps",
4546
"pythonsd",
4647
]
4748

pythonsd/sitemap.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from datetime import datetime, timezone
2+
3+
from django.contrib.sitemaps import Sitemap
4+
from django.urls import reverse
5+
6+
7+
class IndexSitemap(Sitemap):
8+
changefreq = 'weekly'
9+
protocol = 'https'
10+
lastmod = datetime(2024, 5, 15, 0, 0, 0, tzinfo=timezone.utc)
11+
priority = 1.0
12+
13+
def items(self):
14+
return [
15+
'index',
16+
]
17+
18+
def location(self, item):
19+
return reverse(item)
20+
21+
22+
class StaticViewSitemap(Sitemap):
23+
changefreq = 'monthly'
24+
protocol = 'https'
25+
lastmod = datetime(2024, 5, 15, 0, 0, 0, tzinfo=timezone.utc)
26+
priority = 0.8
27+
28+
def items(self):
29+
return [
30+
'code-of-conduct',
31+
]
32+
33+
def location(self, item):
34+
return reverse(item)

pythonsd/urls.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
from django.contrib.sitemaps.views import sitemap
12
from django.urls import path
23
from django.urls import re_path
34
from django.views import generic
45

56
from . import views
7+
from .sitemap import IndexSitemap, StaticViewSitemap
8+
9+
sitemaps = {
10+
"index": IndexSitemap,
11+
"static": StaticViewSitemap,
12+
}
613

714

815
urlpatterns = [
@@ -19,6 +26,8 @@
1926
# XHR/Async requests
2027
path(r"xhr/events/", views.UpcomingEventsView.as_view(), name="upcoming_events"),
2128
path(r"xhr/videos/", views.RecentVideosView.as_view(), name="recent_videos"),
29+
path(r"sitemap.xml", sitemap, {"sitemaps": sitemaps},
30+
name="django.contrib.sitemaps.views.sitemap"),
2231
]
2332

2433
# These redirects handle redirecting URLs from the old static site to the new Django site

0 commit comments

Comments
 (0)