#!/usr/bin/env python3
import os
import datetime
import markdown
def load(fn):
with open(fn) as f:
return f.read()
style = load('autogen/html-style')
sitetitle = load('autogen/html-title')
files = []
with open('autogen/html-files') as f:
for line in f:
line = line.strip()
line = line.split(':')
if len(line) != 3: continue
files += [line]
for md,html,pagetitle in files:
fnmd = 'doc/%s.md' % md
fnhtml = 'doc/html/%s.html' % html
output = ''
x = load(fnmd)
x = markdown.markdown(x,extensions=['markdown.extensions.extra','markdown.extensions.tables'])
mtime = datetime.datetime.utcfromtimestamp(os.path.getmtime(fnmd)).strftime('%Y.%m.%d')
output += '\n
\n'
output += style
output += '\n'
output += pagetitle
output += '\n'
output += '\n'
output += '\n'
output += '\n'
output += sitetitle
output += '
\n'
output += '\n'
for submd,subhtml,subpagetitle in files:
if subhtml == html:
output += '
'
output += pagetitle+'\n'
else:
output += '
'
output += '
%s\n' % (subhtml,subpagetitle)
output += '
'
output += '
\n'
output += '
\n'
output += x
output += '
Version:\n'
output += 'This is version %s of the "%s" web page.\n' % (mtime,pagetitle)
output += '\n'
output += '\n'
output += '\n'
output += '\n'
if not os.path.exists(fnhtml) or output != load(fnhtml):
with open(fnhtml+'.new','w') as f:
f.write(output)
os.chmod(fnhtml+'.new',0o444)
os.rename(fnhtml+'.new',fnhtml)