def write_categories(): """Write all the blog posts in categories""" root = bf.util.path_join(blog.path, blog.category_dir) # Add category to left #bf.writer.materialize_template("_templates/categories.mako","categories.html",{"categories_all":blog.all_categories}) #Find all the categories: categories = set() for post in blog.posts: categories.update(post.categories) for category, category_posts in blog.categorized_posts.items(): #Write category RSS feed rss_path = bf.util.fs_site_path_helper( blog.path, blog.category_dir, category.url_name, "feed") feed.write_feed(category_posts,rss_path, "rss.mako") atom_path = bf.util.fs_site_path_helper( blog.path, blog.category_dir, category.url_name, "feed", "atom") feed.write_feed(category_posts, atom_path, "atom.mako") page_num = 1 while True: path = bf.util.path_join(root, category.url_name, str(page_num), "index.html") page_posts = category_posts[:blog.posts_per_page] category_posts = category_posts[blog.posts_per_page:] #Forward and back links if page_num > 1: prev_link = bf.util.site_path_helper( blog.path, blog.category_dir, category.url_name, str(page_num - 1)) else: prev_link = None if len(category_posts) > 0: next_link = bf.util.site_path_helper( blog.path, blog.category_dir, category.url_name, str(page_num + 1)) else: next_link = None env = { "category": category, "posts": page_posts, "prev_link": prev_link, "next_link": next_link } bf.writer.materialize_template("chronological.mako", path, env) #Copy category/1 to category/index.html if page_num == 1: shutil.copyfile( bf.util.path_join(bf.writer.output_dir, path), bf.util.path_join( bf.writer.output_dir, root, category.url_name, "index.html")) #Prepare next iteration page_num += 1 if len(category_posts) == 0: break
def write_categories(): """Write all the blog posts in categories""" root = bf.util.path_join(blog.path, blog.category_dir) #Find all the categories: categories = set() for post in blog.posts: categories.update(post.categories) for category, category_posts in blog.categorized_posts.items(): #Write category RSS feed rss_path = bf.util.fs_site_path_helper( blog.path, blog.category_dir, category.url_name, "feed") feed.write_feed(category_posts,rss_path, "rss.mako") atom_path = bf.util.fs_site_path_helper( blog.path, blog.category_dir, category.url_name, "feed", "atom") feed.write_feed(category_posts, atom_path, "atom.mako") page_num = 1 while True: path = bf.util.path_join(root, category.url_name, str(page_num), "index.html") page_posts = category_posts[:blog.posts_per_page] category_posts = category_posts[blog.posts_per_page:] #Forward and back links if page_num > 1: prev_link = bf.util.site_path_helper( blog.path, blog.category_dir, category.url_name, str(page_num - 1)) else: prev_link = None if len(category_posts) > 0: next_link = bf.util.site_path_helper( blog.path, blog.category_dir, category.url_name, str(page_num + 1)) else: next_link = None env = { "category": category, "posts": page_posts, "prev_link": prev_link, "next_link": next_link } bf.writer.materialize_template("chronological.mako", path, env) #Copy category/1 to category/index.html if page_num == 1: shutil.copyfile( bf.util.path_join(bf.writer.output_dir, path), bf.util.path_join( bf.writer.output_dir, root, category.url_name, "index.html")) #Prepare next iteration page_num += 1 if len(category_posts) == 0: break
def write_tags(): """Write all the blog posts in tags""" root = bf.util.path_join(blog.path, blog.tag_dir) #Find all the tags: tags = set() for post in blog.posts: tags.update(post.tags) for tag, tag_posts in blog.tagged_posts.items(): #Write tag RSS feed rss_path = bf.util.fs_site_path_helper( blog.path, blog.tag_dir, tag.url_name, "feed") feed.write_feed(tag_posts,rss_path, "rss.mako") atom_path = bf.util.fs_site_path_helper( blog.path, blog.tag_dir, tag.url_name, "feed", "atom") feed.write_feed(tag_posts, atom_path, "atom.mako") page_num = 1 while True: path = bf.util.path_join(root, tag.url_name, str(page_num), "index.html") page_posts = tag_posts[:blog.posts_per_page] tag_posts = tag_posts[blog.posts_per_page:] #Forward and back links if page_num > 1: prev_link = bf.util.site_path_helper( blog.path, blog.tag_dir, tag.url_name, str(page_num - 1)) else: prev_link = None if len(tag_posts) > 0: next_link = bf.util.site_path_helper( blog.path, blog.tag_dir, tag.url_name, str(page_num + 1)) else: next_link = None env = { "posts": page_posts, "prev_link": prev_link, "next_link": next_link, "page_heading": "Posts with tag: " + tag.name } bf.writer.materialize_template("chronological.mako", path, env) #Copy tag/1 to tag/index.html if page_num == 1: shutil.copyfile( bf.util.path_join(bf.writer.output_dir, path), bf.util.path_join( bf.writer.output_dir, root, tag.url_name, "index.html")) #Prepare next iteration page_num += 1 if len(tag_posts) == 0: break