diff options
author | guyzmo <guyzmo@leloop.org> | 2011-01-14 11:51:54 +0100 |
---|---|---|
committer | guyzmo <guyzmo@leloop.org> | 2011-01-14 11:51:54 +0100 |
commit | 48c34a6f62e12f7cb2a7a710dc99cb8d53957cfe (patch) | |
tree | f2fd775016309f35ea57a1ee071a9d7231a193f3 /_controllers/blog/archives.py |
init
Diffstat (limited to '_controllers/blog/archives.py')
-rw-r--r-- | _controllers/blog/archives.py | 38 |
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) |