]> git.sur5r.net Git - i3/i3.github.io/blob - _controllers/blog/archives.py
ed9e45f2da1bf86afaa92ffc349fab956adedbc5
[i3/i3.github.io] / _controllers / blog / archives.py
1 ################################################################################
2 ## Archives controller
3 ##
4 ## Writes out yearly, monthly, and daily archives.
5 ## Each archive is navigable to the next and previous archive
6 ## in which posts were made.
7 ################################################################################
8
9 import operator
10
11 from blogofile.cache import bf
12 import chronological
13
14 blog = bf.config.controllers.blog
15
16
17 def run():
18     write_monthly_archives()
19
20
21 def sort_into_archives():
22     #This is run in 0.initial.py
23     for post in blog.posts:
24         link = post.date.strftime("archive/%Y/%m")
25         try:
26             blog.archived_posts[link].append(post)
27         except KeyError:
28             blog.archived_posts[link] = [post]
29     for archive, posts in sorted(
30         blog.archived_posts.items(), key=operator.itemgetter(0), reverse=True):
31         name = posts[0].date.strftime("%B %Y")
32         blog.archive_links.append((archive, name, len(posts)))
33
34
35 def write_monthly_archives():
36     for link, posts in blog.archived_posts.items():
37         name = posts[0].date.strftime("%B %Y")
38         chronological.write_blog_chron(posts, root=link)