shithub: ugh

ref: 50d1e1e5c145616520252b13a8fb52c5500c8403
dir: /bin/md2html/

View raw version
#!/bin/rc -e
rfork e
flagfmt = ''; args = 'a.md a.html'
eval `''{aux/getflags $*} || exec aux/usage
if(! ~ $#* 2) exec aux/usage

md = $1
html = $2

fn expand {
	template = $1
	eval 'cat <<ENDOFTEMPLATE
' ^ `''{cat $template} ^ '
ENDOFTEMPLATE'
}

# Template variables
# TODO: Source these from templates/env or something.
language = 'en'

stub = `{echo $md | sed 's@\..*$@@'}
title = `{sed 's@^# @@; 1q' $stub.md}
head = `''{expand templates/head.html}
body = `''{bin/filter-markdown $stub.md}
body = `''{expand templates/body.html}
expand templates/page.html >$html.tmp
mv $html.tmp $html