David Chambers avatar David Chambers committed 74bf58e

Changed `utils.archives` to work correctly when there are no posts.

Comments (0)

Files changed (1)

     u"\\n<p>Welcome to Mango. ... <strong>Congratulations!</strong></p>"
     """
     cache_key = u'archives:%s' % path_to_posts
-    posts = cache.get(cache_key) # won't conflict with the posts above as this will always be a folder
+    archives = cache.get(cache_key) # won't conflict with the posts above as this will always be a folder
+    if archives:
+        return archives # there is no check for modification time, this is just always current for 5 minutes
+
+    archives = []
+    posts = get_posts(path_to_posts)
     if posts:
-        return posts # there is no check for modification time, this is just always current for 5 minutes
+        dt = posts[0]['meta']['datetime']
+        year, month = dt.year, dt.month
 
-    posts = []
-    these_posts = []
-    for index, post in enumerate(get_posts(path_to_posts)):
-        if index is 0:
-            year = post['meta']['datetime'].year
-            month = post['meta']['datetime'].month
+        these_posts = []
+        for post in posts:
+            dt = post['meta']['datetime']
+            this_year, this_month = dt.year, dt.month
 
-        this_year = post['meta']['datetime'].year
-        this_month = post['meta']['datetime'].month
+            if this_year == year and this_month == month:
+                these_posts.append(post)
+            else:
+                archives.append((year, month, these_posts))
+                year, month = this_year, this_month
+                these_posts = [post]
 
-        if this_year == year and this_month == month:
-            these_posts.append(post)
-        else:
-            posts.append((year, month, these_posts))
-            year, month = this_year, this_month
-            these_posts = [post]
+        archives.append((year, month, these_posts))
 
-    posts.append((year, month, these_posts))
-    cache.set(cache_key, posts, INDEX_CACHE_SECONDS)
-    return posts
+    cache.set(cache_key, archives, INDEX_CACHE_SECONDS)
+    return archives
 
 def primary_author_email():
     """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.