Skip to content

Commit 62465a2

Browse files
authored
Merge pull request #130 from Jer-Pha/jer-pha1
feat: add sitemap framework
2 parents d0c1ee2 + ef765e5 commit 62465a2

File tree

3 files changed

+40
-0
lines changed

3 files changed

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