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.json.tmp;

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

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 $@
