summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2014-11-08 16:31:38 -0600
committerDan McGee <dan@archlinux.org>2014-11-08 16:31:38 -0600
commit96a7614285325b693434f3fd011238000d75926d (patch)
tree243fab620a9fa57cd93c2412bde1f7190373caf0
parent4c5b478543184ea395e0e692d3bcf666fb7513ad (diff)
Add a news-specific sitemap
This follows the spec at https://support.google.com/news/publisher/answer/74288?hl=en#tagdefinitions Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--sitemaps.py7
-rw-r--r--templates/sitemaps/news_sitemap.xml.jinja14
-rw-r--r--urls.py9
3 files changed, 29 insertions, 1 deletions
diff --git a/sitemaps.py b/sitemaps.py
index eb4e05d9..fb81357e 100644
--- a/sitemaps.py
+++ b/sitemaps.py
@@ -98,6 +98,13 @@ class NewsSitemap(Sitemap):
return 'yearly'
+class RecentNewsSitemap(NewsSitemap):
+ def items(self):
+ now = datetime.utcnow().replace(tzinfo=utc)
+ cutoff = now - timedelta(days=30)
+ return super(RecentNewsSitemap, self).items().filter(postdate__gte=cutoff)
+
+
class ReleasesSitemap(Sitemap):
changefreq = "monthly"
diff --git a/templates/sitemaps/news_sitemap.xml.jinja b/templates/sitemaps/news_sitemap.xml.jinja
new file mode 100644
index 00000000..97dd17b5
--- /dev/null
+++ b/templates/sitemaps/news_sitemap.xml.jinja
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">
+{% for url in urlset %}<url>
+<loc>{{ url.location }}</loc>
+{% if url.lastmod %}<lastmod>{{ url.lastmod|date("Y-m-d") }}</lastmod>{% endif %}
+{% if url.changefreq %}<changefreq>{{ url.changefreq }}</changefreq>{% endif %}
+{% if url.priority %}<priority>{{ url.priority }}</priority>{% endif %}
+<news:news>
+ <news:publication><news:name>Arch Linux News</news:name><news:language>en</news:language></news:publication>
+ {% if url.item.postdate %}<news:publication_date>{{ url.item.postdate|date("c") }}</news:publication_date>{% endif %}
+ {% if url.item.title %}<news:title>{{ url.item.title }}</news:title>{% endif %}
+</news:news>
+</url>{% endfor %}
+</urlset>
diff --git a/urls.py b/urls.py
index 6d896b3c..c35baedf 100644
--- a/urls.py
+++ b/urls.py
@@ -18,6 +18,8 @@ our_sitemaps = {
'releases': sitemaps.ReleasesSitemap,
}
+news_sitemaps = { 'news': sitemaps.RecentNewsSitemap }
+
urlpatterns = []
# Public pages
@@ -81,7 +83,12 @@ urlpatterns += patterns('',
{'sitemaps': our_sitemaps, 'sitemap_url_name': 'sitemaps'}),
(r'^sitemap-(?P<section>.+)\.xml$',
cache_page(1831)(sitemap_views.sitemap),
- {'sitemaps': our_sitemaps, 'template_name': 'sitemaps/sitemap.xml.jinja'}, 'sitemaps'),
+ {'sitemaps': our_sitemaps, 'template_name': 'sitemaps/sitemap.xml.jinja'},
+ 'sitemaps'),
+ (r'^news-sitemap\.xml$',
+ cache_page(1831)(sitemap_views.sitemap),
+ {'sitemaps': news_sitemaps, 'template_name': 'sitemaps/news_sitemap.xml.jinja'},
+ 'news-sitemap'),
)
# Authentication / Admin