#!/usr/bin/python

import common

template = '''\
<p class="dateline">
%(dateline)s
</p>

<div class="artbody">
<p>
%(body)s
</p>
</div>

<p class="artcontrol"> - Tom |
<a href="/blog/%(permalink)s">permalink</a> |
<a href="/blog/%(permalink)s#comments">%(comments)s</a> |
<a href="/viewcvs.cgi/blog/%(filename)s">changelog</a> |
Last updated: %(lastmodified)s
</p>
'''


def index(suffix='.blog.txt', title='Intermediate Form'):
    rows = [ ]

    for bp in common.blog_posts(common.front_page_posts, suffix):
        subs = bp.subs()

        cl = len(bp.comments)
        if cl == 0:
            subs['comments'] = 'no comments'
        elif cl == 1:
            subs['comments'] = '1 comment'
        else:
            subs['comments'] = '%d comments' % cl

        subs['content'] = template % subs

        rows.append(subs)

    subs = {}
    subs['title'] = title

    return common.format_page(subs, rows)

def main():
    f = file(common.webdir + "/index.shtml", "w")
    f.write(index())
    f.close()
    
if __name__ == "__main__":
    main()

