Commit 250fa087 authored by Dan McGee's avatar Dan McGee
Browse files

Use varying changefreq in news sitemap

For those items less than one day old, mark change frequency as 'daily';
for those less than one week old, mark as 'weekly'. Finally, bump
everything else up from 'never' to 'yearly' to ensure it gets crawled at
least once in a while.

Signed-off-by: default avatarDan McGee <>
parent c81aa895
from datetime import datetime, timedelta
from django.contrib.sitemaps import Sitemap
from django.core.urlresolvers import reverse
......@@ -17,8 +19,8 @@ def lastmod(self, obj):
class PackageFilesSitemap(PackagesSitemap):
changefreq = "monthly"
priority = "0.3"
changefreq = "weekly"
priority = "0.2"
def location(self, obj):
return PackagesSitemap.location(self, obj) + 'files/'
......@@ -57,15 +59,26 @@ def location(self, obj):
class NewsSitemap(Sitemap):
changefreq = "never"
priority = "0.8"
def __init__(self):
now = datetime.utcnow()
self.one_day_ago = now - timedelta(days=1)
self.one_week_ago = now - timedelta(days=7)
def items(self):
return News.objects.all()
def lastmod(self, obj):
return obj.last_modified
def changefreq(self, obj):
if obj.last_modified > self.one_day_ago:
return 'daily'
if obj.last_modified > self.one_week_ago:
return 'weekly'
return 'yearly'
class BaseSitemap(Sitemap):
base_viewnames = (
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment