Incremental build of the website

def build(config):
    """Incremental build of the website"""
    logger.info("\nRendering website now...\n")
    logger.info("entries:")
    tags = dict()
    entries = list()
    for post, post_id in find_new_posts_and_pages(DB):
        # this method will also parse the post's tags and
        # update the db collection containing the tags.
        if post.render():
            if post.header['kind'] in ['writing', 'link']:
                for tag in post.tags:
                    tag.posts = [post_id]
                    tags[tag.name] = tag
                entries.append(post)
            logger.info("%s" % post.path)

    for name, to in tags.items():
        logger.info("updating tag %s" % name)
        to.render()

    # This is expensive, we should insert only the recent entries
    # to the index using BeautifulSoup
    # update index
    logger.info("Updating index")
    last_entries, all_entries = _get_last_entries(DB, config['INDEX_SIZE'])
    last_entries = list(_filter_none_public(last_entries))
    update_index(last_entries)

    # update archive
    logger.info("Updating archive")

    # This is expensive, we should insert only the recent entries
    # to the archive using BeautifulSoup

    entries = [Entry.entry_from_db(
               os.path.join(CONFIG['content_root'],
                            e.get('filename')), e.doc_id) for e in
               DB.posts.all()]
    all_entries = list(_filter_none_public(all_entries))
    all_entries.sort(key=operator.attrgetter('date'), reverse=True)
    render_archive(all_entries[config['ARCHIVE_SIZE']:])