diff piecrust/sources/posts.py @ 281:0641fe5c3ef9

serve: Don't crash when a post URL doesn't match our expectations. It can happen that a posts source's URL pattern matches that of something else, like a taxonomy page. In this case, don't crash when what we think will be integers turn out to be something else. Instead, just return that no page has been found.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 01 Mar 2015 21:41:05 -0800
parents ba857c693c72
children dd25bd3ce1f9
line wrap: on
line diff
--- a/piecrust/sources/posts.py	Sun Mar 01 21:39:26 2015 -0800
+++ b/piecrust/sources/posts.py	Sun Mar 01 21:41:05 2015 -0800
@@ -38,12 +38,15 @@
         day = metadata.get('day')
         slug = metadata.get('slug')
 
-        if year is not None:
-            year = int(year)
-        if month is not None:
-            month = int(month)
-        if day is not None:
-            day = int(day)
+        try:
+            if year is not None:
+                year = int(year)
+            if month is not None:
+                month = int(month)
+            if day is not None:
+                day = int(day)
+        except ValueError:
+            return None, None
 
         ext = metadata.get('ext')
         if ext is None: