shithub: ugh

ref: 6c8cdffcbb31b74008f8fa14a26d6ad524850802
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'
}

fn cfg {
	echo -n `''{sed 1q cfg/$1 >[2]/dev/null}
}

language = `{cfg language}
site = `{cfg site}

stub = `{echo $md | sed 's@\..*$@@'}
title = `{sed 's@^# @@; 1q' $stub.md}
if(! ~ $#site 0)
	title = $site — $title
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