52 lines
1.5 KiB
Makefile
52 lines
1.5 KiB
Makefile
SHELL := /bin/bash
|
|
|
|
# CSS to be included as stylesheets and alternate stylesheets
|
|
CSS := assets/ghost-dark.css
|
|
ALTCSS := assets/ghost.css
|
|
|
|
MDFILES := $(wildcard *.md)
|
|
TARGETS := $(patsubst %.md,%.html,$(MDFILES))
|
|
CSSINC := css.inc
|
|
|
|
# our main html5 template, mostly taken from :
|
|
# https://github.com/jgm/pandoc-templates/blob/master/default.html5
|
|
TEMPLATE := assets/pandoc-template.html5
|
|
|
|
define ADD_LINE
|
|
printf '<link rel="%s" href="%s" title="%s">\n' "$(2)" "$(1)" "$(notdir $(basename $(1)))" >> $(3);
|
|
endef
|
|
|
|
# provide a title to pandoc. We take the first line starting with '#',
|
|
# and remove initial '#' and spaces
|
|
TITLE = $(shell sed -n '0,/^\#/ s/^[\# ]*//p' $1)
|
|
|
|
OPTS = --standalone --include-in-header=$(CSSINC) --template=$(TEMPLATE) \
|
|
--from=gfm --to=html5
|
|
|
|
.PHONY: titles all html clean
|
|
|
|
#all: $(CSSINC) titles html
|
|
all: $(CSSINC) html
|
|
|
|
html: $(TARGETS)
|
|
|
|
clean:
|
|
@echo cleaning $(TARGETS) $(CSSINC)
|
|
@rm -f $(TARGETS) $(CSSINC)
|
|
|
|
$(CSSINC): $(CSS) $(ALTCSS)
|
|
@echo generating $@
|
|
@#echo deps=$^
|
|
@rm -f $@
|
|
@$(foreach css,$(CSS),$(call ADD_LINE,$(css),stylesheet,$@))
|
|
@$(foreach css,$(ALTCSS),$(call ADD_LINE,$(css),alternate stylesheet,$@))
|
|
|
|
%.html: %.md $(CSSINC)
|
|
@echo -n "generating $@... "
|
|
@if ! grep -q "^#" $< ; then \
|
|
echo "ERROR (no title), skipping." ; \
|
|
else \
|
|
pandoc $(OPTS) --metadata=title:"$(call TITLE,$<)" -o $@ $< ; \
|
|
echo done. ; \
|
|
fi
|