vpath %.md srb

########## Variables ##########

dependencies = lowdown

markdown = $(wildcard srb/**/*.md)

pages = $(patsubst srb/%.md, public/%.html, $(markdown))

targets += $(pages)

ignored += public/

ignore_file = .git/info/exclude

########## Build Instructions ##########

.PHONY: help
help: ## Print the help message.
	@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z._-]+:.*?## / {printf "\033[36m%s\033[0m : %s\n", $$1, $$2}' $(MAKEFILE_LIST) | \
		sort | \
		column -s ':' -t

.PHONY: check
check: ## Check you have all dependencies.
	@$(foreach dep, $(dependencies), \
		command -v $(dep) >/dev/null || { echo Install $(dep) && exit 1 ;} ;\
	)

.PHONY: site
site: $(targets) $(ignore_file) ## Make the website in public/.

$(ignore_file): $(MAKEFILE_LIST)
	echo $(ignored) | tr ' ' '\n' > $@

public/:
	mkdir $@

$(pages): public/%.html: %.md | public/
	@mkdir -p $(@D)
	@sed 's/\(\[.*\)\(.*\)\.md)/\1)/g' $< |\
	lowdown -m filename=$(basename $@) -s --template default.html > $@
	$(info making $@)

.PHONY: clean
clean: ## Remove generated files.
	$(RM) $(targets)
