TOP_DIR = ../.. OUT_DIR = $(TOP_DIR)/public EXTENSIONS = md org V = 0 v = $(call v_$(V),$(1),$(2)) v_0 = @echo $(1) $(2); v_1 = dirname = $(patsubst %/,%,$(dir $(1))) dirnames = $(sort $(call dirname,$(1))) page_patterns = $(foreach ext,$(EXTENSIONS),'$(TOP_DIR)/**.$(ext)') page_folders = $(call dirnames,$(shell git ls-files $(page_patterns))) top_readme = $(shell git ls-files $(addprefix $(TOP_DIR)/README.,$(EXTENSIONS))) html_template = template.html lua_filters = convert-internal-links.lua 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 # Lua module to let filters know about the configuration. lua_config = $(cache)/config.lua # Defines $(pages) and $(indices). dependencies = $(cache)/deps.mk $(title): $(top_readme) | $(cache) pandoc --lua-filter print-title.lua $< > $@ $(site_tree): $(page_folders) | $(cache) ./generate-tree.py -o $@ $(EXTENSIONS) $(lua_config): | $(cache) ./generate-lua-config.py EXTENSIONS="$(EXTENSIONS)" > $@ $(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 $(page_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) $(subindices): $(title) $(pages) $(indices): $(html_template) $(lua_filters) $(lua_config) $(pages): $(OUT_DIR)/%.html: $(call v,PAGE,$*) \ ./generate-page.py --site-title="$$(cat $(title))" --title="$*" \ $(foreach f,$(lua_filters),--lua-filter $(f)) \ --template=$(html_template) $< $@ top_index = $(OUT_DIR)/index.html subindices = $(filter-out $(top_index),$(indices)) $(top_index): index_options = $(subindices): index_options = --site-title="$$(cat $(title))" # ⚠ When tweaking this rule, check whether it still works for the # top-level index.html. $(indices): $(OUT_DIR)/%index.html: $(call v,INDEX,$*) \ ./generate-index.py $(index_options) --template=$(html_template) \ $(foreach f,$(lua_filters),--lua-filter $(f)) \ $(site_tree) "$(patsubst %/,%,$*)" $@ clean: -rm -r $(cache) -rm -r $(OUT_DIR)