diff options
author | Dan McGee <dan@archlinux.org> | 2012-03-15 22:08:10 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-03-16 15:14:15 +0100 |
commit | 250fa087c990957682d65fb1d1af89a1a176b84f (patch) | |
tree | 020ecd3af7909f453fbee595facb0b54e208efc1 | |
parent | c81aa8955dd5992f7039e1640243325c82d011cc (diff) | |
download | archweb-250fa087c990957682d65fb1d1af89a1a176b84f.tar.gz archweb-250fa087c990957682d65fb1d1af89a1a176b84f.tar.xz |
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 <dan@archlinux.org>
-rw-r--r-- | sitemaps.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/sitemaps.py b/sitemaps.py index 958d1f4..177555f 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 = ( |