Skip to content

Commit

Permalink
add sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
sgmdlt committed Oct 21, 2024
1 parent fab82d1 commit 7aaea37
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 12 deletions.
3 changes: 3 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'django_extensions',
'mathfilters',
'django_filters',
'django.contrib.sitemaps'
]

MIDDLEWARE = [
Expand Down Expand Up @@ -288,3 +289,5 @@
'LOCATION': 'unique-snowflake',
}
}

SITE_ID = 1
4 changes: 4 additions & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from django.conf import settings
from django.contrib.sitemaps.views import sitemap
from django.contrib.staticfiles.views import serve
from django.urls import include, path
from django.views.i18n import JavaScriptCatalog

from contributors.admin.custom import site
from contributors.sitemap import sitemaps


def trigger_error(request):
Expand All @@ -20,6 +22,8 @@ def trigger_error(request):
path('', include('contributors.urls')),
path('sentry-debug/', trigger_error),
path('robots.txt', serve, {'path': 'robots.txt'}),
path('sitemap.xml', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
]

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

from contributors.models import (
Contributor,
Organization,
Project,
Repository,
)


class StaticViewSitemap(Sitemap):
priority = 0.5
changefreq = 'weekly'

def items(self):
return [
'contributors:home',
'contributors:about',
'contributors:landing',
'contributors:achievements'
]

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


class OrganizationSitemap(Sitemap):
changefreq = "monthly"
priority = 0.7

def items(self):
return Organization.objects.all()

def location(self, item):
return reverse('contributors:organization_details', args=[item.name])


class RepositorySitemap(Sitemap):
changefreq = "weekly"
priority = 0.7

def items(self):
return Repository.objects.all()

def location(self, item):
return reverse('contributors:repository_details', args=[item.name])


class ContributorSitemap(Sitemap):
changefreq = "weekly"
priority = 0.6

def items(self):
return Contributor.objects.all()

def location(self, item):
return reverse('contributors:contributor_details', args=[item.login])


class ProjectSitemap(Sitemap):
changefreq = "weekly"
priority = 0.6

def items(self):
return Project.objects.all()

def location(self, item):
return reverse('contributors:project_details', args=[item.pk])


sitemaps = {
'static': StaticViewSitemap,
'organizations': OrganizationSitemap,
'repositories': RepositorySitemap,
'contributors': ContributorSitemap,
'projects': ProjectSitemap,
}
23 changes: 11 additions & 12 deletions static/robots.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
User-agent: *
Allow: /repositories/$
Allow: /issues/$
Allow: /organizations/$
Allow: /leaderboard/$
Allow: /contributors/$
Allow: /projects/$
Disallow: /repositories/?
Disallow: /issues/?
Disallow: /organizations/?
Disallow: /leaderboard/?
Disallow: /contributors/?
Disallow: /projects/?
Disallow: /repositories/*?
Disallow: /issues/*?
Disallow: /organizations/*?
Disallow: /leaderboard/*?
Disallow: /contributors/*?
Disallow: /projects/*?
Disallow: /*page=
Disallow: /*sort=
Disallow: /*labels=
Disallow: /admin/
Crawl-delay: 10

Sitemap: https://hexlet-friends.herokuapp.com/sitemap.xml

0 comments on commit 7aaea37

Please sign in to comment.