summaryrefslogtreecommitdiffstats
path: root/_controllers/blog/archives.py
diff options
context:
space:
mode:
Diffstat (limited to '_controllers/blog/archives.py')
-rw-r--r--_controllers/blog/archives.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/_controllers/blog/archives.py b/_controllers/blog/archives.py
new file mode 100644
index 0000000..ed9e45f
--- /dev/null
+++ b/_controllers/blog/archives.py
@@ -0,0 +1,38 @@
+################################################################################
+## Archives controller
+##
+## Writes out yearly, monthly, and daily archives.
+## Each archive is navigable to the next and previous archive
+## in which posts were made.
+################################################################################
+
+import operator
+
+from blogofile.cache import bf
+import chronological
+
+blog = bf.config.controllers.blog
+
+
+def run():
+ write_monthly_archives()
+
+
+def sort_into_archives():
+ #This is run in 0.initial.py
+ for post in blog.posts:
+ link = post.date.strftime("archive/%Y/%m")
+ try:
+ blog.archived_posts[link].append(post)
+ except KeyError:
+ blog.archived_posts[link] = [post]
+ for archive, posts in sorted(
+ blog.archived_posts.items(), key=operator.itemgetter(0), reverse=True):
+ name = posts[0].date.strftime("%B %Y")
+ blog.archive_links.append((archive, name, len(posts)))
+
+
+def write_monthly_archives():
+ for link, posts in blog.archived_posts.items():
+ name = posts[0].date.strftime("%B %Y")
+ chronological.write_blog_chron(posts, root=link)