# BENZIN Makefile BASE_URL=https://example.com PANDOC_ARGS=--from=gfm+emoji --to=html --section-divs PAGE_TEMPLATE=templates/page.html OPENRING_TEMPLATE=templates/openring.html RSS_TEMPLATE=templates/rss.xml RSS_ITEM_TEMPLATE=templates/rss_item.xml RSS=out/blog/index.xml OPENRING_FOOTER=tmp/openring.html OPENRING_ARGS=-s https://eug-vs.xyz/blog/index.xml -s https://drewdevault.com/blog/index.xml BLOG_SOURCES=$(wildcard src/blog/*.md) SOURCES=$(wildcard src/*.md) $(BLOG_SOURCES) TMP_HTML=$(patsubst src/%.md, tmp/%.content.html, $(SOURCES)) HTML=$(patsubst src/%.md, out/%.html, $(SOURCES)) BLOG_XML=$(patsubst src/%.md, tmp/%.xml, $(BLOG_SOURCES)) .PHONY: clean all .SECONDARY: $(TMP_HTML) $(BLOG_XML) all: $(HTML) $(RSS) out/%.html: tmp/%.content.html tmp/%.meta.title $(PAGE_TEMPLATE) $(OPENRING_FOOTER) @mkdir -p $(@D) sed "/<\/main>/e cat $< $(OPENRING_FOOTER)" $(PAGE_TEMPLATE) > $@ sed -i \ -e '//{' \ -e 'a ' -e "r tmp/$*.meta.title" -e 'a <\/title>' \ -e '}' $@ tmp/%.content.html: src/%.md @mkdir -p $(@D) pandoc $(PANDOC_ARGS) $< > $@ tmp/%.meta.title: src/%.md @mkdir -p $(@D) sed '/^#/q' $< | sed 's/#* //' > $@ $(RSS): $(BLOG_XML) $(RSS_TEMPLATE) @mkdir -p $(@D) sed "/<\/channel>/e cat $(BLOG_XML)" $(RSS_TEMPLATE) > $@ tmp/%.xml: tmp/%.content.html tmp/%.meta.title $(RSS_ITEM_TEMPLATE) @mkdir -p $(@D) sed "/CDATA/r $<" $(RSS_ITEM_TEMPLATE) > $@ sed -i \ -e '/<item>/{' \ -e 'a <title>' -e "r tmp/$*.meta.title" -e 'a <\/title>' \ -e "a <link>$(BASE_URL)/$*.html<\/link>" \ -e '}' $@ $(OPENRING_FOOTER): $(OPENRING_TEMPLATE) @mkdir -p $(@D) openring $(OPENRING_ARGS) < $< > $@ clean: rm -rf tmp out