template := pandoc/template.html
style := pandoc/style.css

article_list := articles.json
list_template := 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 $(notdir $@); \
	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) --highlight-style zenburn --mathml --toc --output $@

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