Fix a few bugs in generating blog index pages

Also refactored b so that the code base is smaller and easier to
maintain. Namely separated out replicated code such as preparing input
directory, output directory and also template files to generate the blog
index pages.