template := $(abspath ./pandoc/template.html)
style := $(abspath ./pandoc/style.css)

article_list := $(abspath ./articles.json)
list_template := $(abspath ./pandoc/meta-json-template.txt)

articles := $(patsubst %.md,%.html,$(wildcard articles/*.md))

all: index.html about.html

clean:
	echo '{"articles": []}' > $(article_list); \
	rm $(articles); \
	rm index.html about.html;

$(articles): %.html: %.md
	pandoc $< --template $(template) --css $(style) --highlight-style zenburn --mathml --toc --output $@; \
	jq '.articles += [$(shell pandoc $< --template $(list_template))]' $(article_list) > articles.json.tmp; 
	cat ./articles.json.tmp > articles.json;
	rm ./articles.json.tmp;

index.html: index.md $(articles)
	pandoc $< --template $(template) --css $(style) --metadata-file $(article_list) --output $@

about.html: about.md
	pandoc $< --template $(template) --css $(style) --output $@
