.SUFFIXES: .md .html

# configuration
SRCDIR = foo.tld
# markdown converter
MDTOHTML = lowdown \
	-D html-skiphtml \
	-D html-head-ids \
	-E smarty \
	-d metadata \
	--html-no-skiphtml \
	--html-no-escapehtml
SSHCRED = user@foo.tld
REMOTEDIR = /var/www/htdocs/foo.tld/
# ---

SRC != find $(SRCDIR) -type f -name \*.md
OUT = ${SRC:.md=.html}


all: $(OUT) $(SRCDIR)/all.html $(SRCDIR)/sitemap.xml

clean:
	find . -name \*.html -delete

.md.html:
	@echo $<
	@cat head.tpl > $@
	@$(MDTOHTML) $< >> $@
	@cat foot.tpl  >> $@
	@bin/title.sh $@

$(SRCDIR)/sitemap.xml: $(OUT)
	@echo sitemap
	@bin/sitemap.sh $(OUT) > $(SRCDIR)/sitemap.xml
	@gzip --best -c $(SRCDIR)/sitemap.xml > $(SRCDIR)/sitemap.gz

$(SRCDIR)/all.html: $(OUT)
	@echo $@
	@cat head.tpl > $@
	@bin/all.sh $(OUT) | $(MDTOHTML) >> $@
	@cat foot.tpl  >> $@
	@bin/title.sh $@

serve:
	cd $(SRCDIR) && python3 -m http.server

entr:
	find . -type f -name \*.md | entr make

upload:
	openrsync -e "ssh" -av $(SRCDIR)/ $(SSHCRED):$(REMOTEDIR)
