~kvik/ugh

50d1e1e5c145616520252b13a8fb52c5500c8403 — kvik 4 years ago 97ea5f9
Add the programs
3 files changed, 54 insertions(+), 0 deletions(-)

A bin/filter-markdown
A bin/md2html
A mkfile
A bin/filter-markdown => bin/filter-markdown +2 -0
@@ 0,0 1,2 @@
#!/bin/rc
exec markdown -T -f toc $*

A bin/md2html => bin/md2html +27 -0
@@ 0,0 1,27 @@
#!/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

A mkfile => mkfile +25 -0
@@ 0,0 1,25 @@
articles = `{walk -f data/}
articles = ${articles:data/%=public/%}
md =    `{{for(i in $articles) echo $i}| grep '\.md$'}
txt =   `{{for(i in $articles) echo $i}| grep '\.txt$'}
shtml = `{{for(i in $articles) echo $i}| grep '\.shtml$'}
articles = ${md:   public/%.md=   public/%.html} \
           ${shtml:public/%.shtml=public/%.html} \
           $md $txt

all:V: $articles

clean:V:
	rm -rf $articles

public/%.html: data/%.md
	bin/md2html data/$stem.md $target

public/%.html: data/%.shtml
	cp data/$stem.shtml $target

public/%.md: data/%.md
	cp data/$stem.md $target

public/%.txt: data/%.txt
	cp data/$stem.txt $target