shithub: ugh

ref: 3a98ba214a1ca2f61c45499e1fe4194a4c5373a0
dir: ugh/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