1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
TOP_DIR = ../..
OUT_DIR = $(TOP_DIR)/public
TEXT_FILES = 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)))
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)))
html_template = template.html
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) $(subindices): $(title)
$(pages) $(indices): $(html_template)
$(pages): $(OUT_DIR)/%.html:
$(call v,PAGE,$*) TEXT_FILES="$(TEXT_FILES)" \
./generate-page.py --site-title="$$(cat $(title))" --title="$*" \
--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,$*) TEXT_FILES="$(TEXT_FILES)" \
./generate-index.py $(index_options) --template=$(html_template) \
$(site_tree) "$(patsubst %/,%,$*)" $@
clean:
-rm -r $(cache)
-rm -r $(OUT_DIR)
|