Skip to content

feat: add sitemap framework #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sitemaps",
"pythonsd",
]

Expand Down
30 changes: 30 additions & 0 deletions pythonsd/sitemap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.contrib.sitemaps import Sitemap
from django.urls import reverse


class IndexSitemap(Sitemap):
changefreq = 'weekly'
protocol = 'https'
priority = 1.0

def items(self):
return [
'index',
]

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


class StaticViewSitemap(Sitemap):
changefreq = 'monthly'
protocol = 'https'
priority = 0.8

def items(self):
return [
'code-of-conduct',
]

def location(self, item):
return reverse(item)
9 changes: 9 additions & 0 deletions pythonsd/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from django.contrib.sitemaps.views import sitemap
from django.urls import path
from django.urls import re_path
from django.views import generic

from . import views
from .sitemap import IndexSitemap, StaticViewSitemap

sitemaps = {
"index": IndexSitemap,
"static": StaticViewSitemap,
}


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

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