TOP_DIR = ../.. OUT_DIR = $(TOP_DIR)/public TEXT_FILES = md org dirname = $(patsubst %/,%,$(dir $(1))) dirnames = $(sort $(call dirname,$(1))) text_patterns = $(foreach ext,$(TEXT_FILES),'$(TOP_DIR)/**.$(ext)') text_folders = $(call dirnames,$(shell git ls-files $(text_patterns))) top_readme = $(shell git ls-files $(addprefix $(TOP_DIR)/README.,$(TEXT_FILES))) all: site cache = .cache # Site title, parsed from the top-level README. title = $(cache)/title # Maps folders to their contents (files and subfolders). site_tree = $(cache)/site-tree.json # Defines $(pages) and $(indices). dependencies = $(cache)/deps.mk $(title): $(top_readme) | $(cache) pandoc --lua-filter print-title.lua $< > $@ $(site_tree): $(text_folders) | $(cache) ./generate-tree.py -o $@ $(TEXT_FILES) $(dependencies): $(site_tree) | $(cache) ./generate-deps.py $< $@ $(OUT_DIR) include $(dependencies) site: $(pages) $(indices) # List of output folders. Compute this from the full list of HTML # pages, since $(text_folders) may be missing some intermediate # directories (e.g. folders that only contain subfolders). html_folders = $(call dirnames,$(pages) $(indices)) $(html_folders) $(cache): mkdir -p $@ $(pages) $(indices): $(title) $(pages): $(OUT_DIR)/%.html: pandoc -s $< -o $@ -T "$$(cat $(title))" -M title="$*" # ⚠ When tweaking this rule, check whether it still works for the # top-level index.html. $(indices): $(OUT_DIR)/%index.html: ./generate-index.py $(site_tree) "$$(cat $(title))" "$(patsubst %/,%,$*)" $@ clean: -rm $(dependencies) -rm -r $(OUT_DIR)