site/render.py @ 12d0ec667b63

Implement crash solution given in Google group.

link for Google group:
https://groups.google.com/forum/#!topic/vim_dev/HgKdV33Jy5I
author killphi <killphi@gmx.de>
date Fri, 23 Aug 2013 17:07:07 +0200
parents bbbc99908ae5
children (none)
#!/usr/bin/env python

import os
import markdown

extensions = ['toc']
fns = [f for f in os.listdir('.') if f.endswith('.markdown')
                                  or f.endswith('.mdown')
                                  or f.endswith('.md')]

with open('layout.html') as layoutfile:
    layoutlines = layoutfile.readlines()

for fn in fns:
    name = fn.rsplit('.')[0]
    newfn = name + '.html'

    with open(fn) as mdfile:
        title = mdfile.readline().strip()
        content = markdown.markdown(mdfile.read(), extensions)

    with open(newfn, 'w') as newfile:
        for line in layoutlines:
            line = line.replace('{{ title }}', title)
            line = line.replace('{{ content }}', content)
            newfile.write(line)