mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 10:31:13 -05:00
Refactor code structure and remove redundant changes
This commit is contained in:
119
django-backend/apps/core/sitemaps.py
Normal file
119
django-backend/apps/core/sitemaps.py
Normal file
@@ -0,0 +1,119 @@
|
||||
"""
|
||||
Django Sitemaps for SEO
|
||||
|
||||
Generates XML sitemaps for search engine crawlers to discover and index content.
|
||||
"""
|
||||
|
||||
from django.contrib.sitemaps import Sitemap
|
||||
from django.urls import reverse
|
||||
|
||||
from apps.entities.models import Park, Ride, Company, RideModel
|
||||
|
||||
|
||||
class ParkSitemap(Sitemap):
|
||||
"""Sitemap for theme parks."""
|
||||
|
||||
changefreq = "weekly"
|
||||
priority = 0.9
|
||||
|
||||
def items(self):
|
||||
"""Return all active parks."""
|
||||
return Park.objects.filter(is_active=True).order_by('-updated')
|
||||
|
||||
def lastmod(self, obj):
|
||||
"""Return last modification date."""
|
||||
return obj.updated
|
||||
|
||||
def location(self, obj):
|
||||
"""Return URL for park."""
|
||||
return f'/parks/{obj.slug}/'
|
||||
|
||||
|
||||
class RideSitemap(Sitemap):
|
||||
"""Sitemap for rides."""
|
||||
|
||||
changefreq = "weekly"
|
||||
priority = 0.8
|
||||
|
||||
def items(self):
|
||||
"""Return all active rides."""
|
||||
return Ride.objects.filter(
|
||||
is_active=True
|
||||
).select_related('park').order_by('-updated')
|
||||
|
||||
def lastmod(self, obj):
|
||||
"""Return last modification date."""
|
||||
return obj.updated
|
||||
|
||||
def location(self, obj):
|
||||
"""Return URL for ride."""
|
||||
return f'/parks/{obj.park.slug}/rides/{obj.slug}/'
|
||||
|
||||
|
||||
class CompanySitemap(Sitemap):
|
||||
"""Sitemap for companies/manufacturers."""
|
||||
|
||||
changefreq = "monthly"
|
||||
priority = 0.6
|
||||
|
||||
def items(self):
|
||||
"""Return all active companies."""
|
||||
return Company.objects.filter(is_active=True).order_by('-updated')
|
||||
|
||||
def lastmod(self, obj):
|
||||
"""Return last modification date."""
|
||||
return obj.updated
|
||||
|
||||
def location(self, obj):
|
||||
"""Return URL for company."""
|
||||
return f'/manufacturers/{obj.slug}/'
|
||||
|
||||
|
||||
class RideModelSitemap(Sitemap):
|
||||
"""Sitemap for ride models."""
|
||||
|
||||
changefreq = "monthly"
|
||||
priority = 0.7
|
||||
|
||||
def items(self):
|
||||
"""Return all active ride models."""
|
||||
return RideModel.objects.filter(
|
||||
is_active=True
|
||||
).select_related('manufacturer').order_by('-updated')
|
||||
|
||||
def lastmod(self, obj):
|
||||
"""Return last modification date."""
|
||||
return obj.updated
|
||||
|
||||
def location(self, obj):
|
||||
"""Return URL for ride model."""
|
||||
return f'/models/{obj.slug}/'
|
||||
|
||||
|
||||
class StaticSitemap(Sitemap):
|
||||
"""Sitemap for static pages."""
|
||||
|
||||
changefreq = "monthly"
|
||||
priority = 0.5
|
||||
|
||||
def items(self):
|
||||
"""Return list of static pages."""
|
||||
return ['home', 'about', 'privacy', 'terms']
|
||||
|
||||
def location(self, item):
|
||||
"""Return URL for static page."""
|
||||
if item == 'home':
|
||||
return '/'
|
||||
return f'/{item}/'
|
||||
|
||||
def changefreq(self, item):
|
||||
"""Home page changes more frequently."""
|
||||
if item == 'home':
|
||||
return 'daily'
|
||||
return 'monthly'
|
||||
|
||||
def priority(self, item):
|
||||
"""Home page has higher priority."""
|
||||
if item == 'home':
|
||||
return 1.0
|
||||
return 0.5
|
||||
Reference in New Issue
Block a user