constance

Scripts for generating (an earlier obsolete version of) my personal web site
git clone https://code.djc.id.au/git/constance/
commit 83ed8da5a0f5f8673eac9f0f398432a53a442d81
parent 141a3e1c95559ba5cb9de7dc8e1ef1f02103d14f
Author: Sam Kingston <sam@sjkwi.com.au>
Date:   Sun, 26 Oct 2008 00:58:08 +1000

Handle an empty readinglog in sitemap

Diffstat:
Mapp.py | 6+++++-
Mtemplates/sitemap.xml | 2+-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/app.py b/app.py
@@ -272,12 +272,16 @@ class Constance(object):
                 tags[tag] = max(entry.modified_date, tags.get(tag, datetime.datetime.min))
         sorted_entries = sorted(chain(self.blog_entries, self.readinglog_entries), 
                 key=lambda e: e.publication_date, reverse=True)
+        if len(self.readinglog_entries) != 0:
+            rl_updated = max(e.date for e in self.readlinglog_entries)
+        else:
+            rl_updated = None
         rendered = template_loader.load('sitemap.xml').generate(
                 config=self.config, 
                 environ=self.environ, 
                 blog_entries=self.blog_entries, 
                 tags=tags, 
-                readinglog_updated=max(e.date for e in self.readinglog_entries), 
+                readinglog_updated=rl_updated,
                 index_updated=max(e.modified_date for e in sorted_entries[:self.config.getint('global', 'entries_per_page')]), 
                 ).render('xml', encoding='utf8') # sitemaps must be UTF-8
         return (rendered, [('Content-Type', 'text/xml')])
diff --git a/templates/sitemap.xml b/templates/sitemap.xml
@@ -25,7 +25,7 @@ W3C_TIME_FORMAT = str('%Y-%m-%dT%H:%M:%S+10:00')
     <changefreq>weekly</changefreq>
     <priority>0.25</priority>
 </url>
-<url>
+<url py:if="readinglog_updated is not None">
     <loc>${abs_uri('+reading', '')}</loc>
     <lastmod>${readinglog_updated.strftime(W3C_TIME_FORMAT)}</lastmod>
     <changefreq>weekly</changefreq>