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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
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
stylesheets_src = crumbs.css
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)
stylesheets_dir = $(OUT_DIR)/style
stylesheets = $(foreach s,$(stylesheets_src),$(stylesheets_dir)/$(s))
site: $(pages) $(indices) $(stylesheets) $(stylesheets)
# 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))
top_index = $(OUT_DIR)/index.html
subindices = $(filter-out $(top_index),$(indices))
$(html_folders) $(stylesheets_dir) $(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)) \
$(foreach s,$(stylesheets_src),--stylesheet style/$(s)) \
--template=$(html_template) $< $@
$(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)) \
$(foreach s,$(stylesheets_src),--stylesheet style/$(s)) \
$(site_tree) "$(patsubst %/,%,$*)" $@
$(stylesheets): $(stylesheets_dir)/%.css: %.css | $(stylesheets_dir)
cp $< $@
clean:
-rm -r $(cache)
-rm -r $(OUT_DIR)
|