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 $(notdir $(articles)); \
	rm index.html about.html;


$(articles): %.html: %.md
	pandoc $< --template $(abspath $(template)) --css $(abspath $(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) --output $@

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