From 250fa087c990957682d65fb1d1af89a1a176b84f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 15 Mar 2012 16:08:10 -0500 Subject: 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: Dan McGee --- sitemaps.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'sitemaps.py') diff --git a/sitemaps.py b/sitemaps.py index 958d1f44..177555ff 100644 --- a/sitemaps.py +++ b/sitemaps.py @@ -1,3 +1,5 @@ +from datetime import datetime, timedelta + from django.contrib.sitemaps import Sitemap from django.core.urlresolvers import reverse @@ -17,8 +19,8 @@ class PackagesSitemap(Sitemap): 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 @@ class SplitPackagesSitemap(Sitemap): 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 = ( -- cgit v1.2.3-55-g3dc8