Makefile (2864B)
1 TOP_DIR = ../.. 2 OUT_DIR = $(TOP_DIR)/public 3 EXTENSIONS = md org 4 V = 0 5 6 v = $(call v_$(V),$(1),$(2)) 7 v_0 = @echo $(1) $(2); 8 v_1 = 9 10 dirname = $(patsubst %/,%,$(dir $(1))) 11 dirnames = $(sort $(call dirname,$(1))) 12 13 page_patterns = $(foreach ext,$(EXTENSIONS),'$(TOP_DIR)/**.$(ext)') 14 page_folders = $(call dirnames,$(shell git ls-files $(page_patterns))) 15 top_readme = $(shell git ls-files $(addprefix $(TOP_DIR)/README.,$(EXTENSIONS))) 16 html_template = template.html 17 stylesheets_src = crumbs.css 18 lua_filters = convert-internal-links.lua 19 20 all: site 21 22 cache = .cache 23 # Site title, parsed from the top-level README. 24 title = $(cache)/title 25 # Maps folders to their contents (files and subfolders). 26 site_tree = $(cache)/site-tree.json 27 # Lua module to let filters know about the configuration. 28 lua_config = $(cache)/config.lua 29 # Defines $(pages) and $(indices). 30 dependencies = $(cache)/deps.mk 31 32 $(title): $(top_readme) | $(cache) 33 pandoc --lua-filter print-title.lua $< > $@ 34 35 $(site_tree): $(page_folders) | $(cache) 36 ./generate-tree.py -o $@ $(EXTENSIONS) 37 38 $(lua_config): | $(cache) 39 ./generate-lua-config.py EXTENSIONS="$(EXTENSIONS)" > $@ 40 41 $(dependencies): $(site_tree) | $(cache) 42 ./generate-deps.py $< $@ $(OUT_DIR) 43 44 include $(dependencies) 45 46 stylesheets_dir = $(OUT_DIR)/style 47 stylesheets = $(foreach s,$(stylesheets_src),$(stylesheets_dir)/$(s)) 48 49 site: $(pages) $(indices) $(stylesheets) 50 51 # List of output folders. Compute this from the full list of HTML 52 # pages, since $(page_folders) may be missing some intermediate 53 # directories (e.g. folders that only contain subfolders). 54 html_folders = $(call dirnames,$(pages) $(indices)) 55 56 top_index = $(OUT_DIR)/index.html 57 subindices = $(filter-out $(top_index),$(indices)) 58 59 $(html_folders) $(stylesheets_dir) $(cache): 60 mkdir -p $@ 61 62 $(pages) $(subindices): $(title) 63 64 $(pages) $(indices): $(html_template) $(lua_filters) $(lua_config) 65 66 $(pages): $(OUT_DIR)/%.html: 67 $(call v,PAGE,$*) \ 68 ./generate-page.py --site-title="$$(cat $(title))" --title="$*" \ 69 $(foreach f,$(lua_filters),--lua-filter $(f)) \ 70 $(foreach s,$(stylesheets_src),--stylesheet style/$(s)) \ 71 --template=$(html_template) $< $@ 72 73 $(top_index): index_options = 74 $(subindices): index_options = --site-title="$$(cat $(title))" 75 76 # ⚠ When tweaking this rule, check whether it still works for the 77 # top-level index.html. 78 $(indices): $(OUT_DIR)/%index.html: 79 $(call v,INDEX,$*) \ 80 ./generate-index.py $(index_options) --template=$(html_template) \ 81 $(foreach f,$(lua_filters),--lua-filter $(f)) \ 82 $(foreach s,$(stylesheets_src),--stylesheet style/$(s)) \ 83 $(site_tree) "$(patsubst %/,%,$*)" $@ 84 85 $(stylesheets): $(stylesheets_dir)/%.css: %.css | $(stylesheets_dir) 86 cp $< $@ 87 88 clean: 89 -rm -r $(cache) 90 -rm -r $(OUT_DIR)