-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
266 lines (231 loc) · 9.82 KB
/
Makefile
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# Pandit - Minimalist Pandoc-based static site generator
# https://p2pcollab.net/pandit/
MD := $(shell git ls-files | grep '\.md$$')
ORG := $(shell git ls-files | grep '\.org$$')
RST := $(shell git ls-files | grep '\.rst$$')
ADOC := $(shell git ls-files | grep '\.adoc$$')
DOT := $(shell git ls-files | grep '\.dot$$')
MD_HTML := $(patsubst %.md,%.md.html,$(MD))
ORG_HTML := $(patsubst %.org,%.org.html,$(ORG))
RST_HTML := $(patsubst %.rst,%.rst.html,$(RST))
ADOC_HTML := $(patsubst %.adoc,%.adoc.html,$(ADOC))
MD_PDF := $(patsubst %.md,%.md.pdf,$(MD))
ORG_PDF := $(patsubst %.org,%.org.pdf,$(ORG))
RST_PDF := $(patsubst %.rst,%.rst.pdf,$(RST))
ADOC_PDF := $(patsubst %.adoc,%.adoc.pdf,$(ADOC))
MD_TEX := $(patsubst %.md,%.md.tex,$(MD))
ORG_TEX := $(patsubst %.org,%.org.tex,$(ORG))
RST_TEX := $(patsubst %.rst,%.rst.tex,$(RST))
ADOC_TEX := $(patsubst %.adoc,%.adoc.tex,$(ADOC))
DOT_SVG := $(patsubst %.dot,%.svg,$(DOT))
# Input/output directory names
OUT := public
OUT_CSS := css
OUT_LIB := lib
IMG := img
# CSS to be included directly in HTML documents
CSS := $(shell test -e css.mk && cat css.mk)
# Extra CSS to publish
CSS_X := $(shell test -e css-x.mk && cat css-x.mk)
KATEX_URL := https://cdn.jsdelivr.net/npm/katex@0.16.0/dist
PANDOC_OPTS := \
--data-dir=. \
--section-divs
PANDOC_OPTS_HTML := $(shell test -e html.mk && cat html.mk)
PANDOC_OPTS_PDF := $(shell test -e pdf.mk && cat pdf.mk) \
--pdf-engine=xelatex
# Publish to web server with filename extensions and index.html removed from links
WEB :=
LINK_REGEX := \
s/href="\([^\":]*\)\.\(md\|org\|rst\|adoc\)\(\#[^\"]*\)\?"/href="\1.html\3"/g;\
$(if $(WEB),$\
s/href="\([^\":]*\)\.html\(#[^\"]*\)\?"/href="\1\2"/g;\
s/href="\([^\":]*\/\)index\(#[^\"]*\)\?"/href="\1\2"/g;\
s/href="index\(#[^\"]*\)\?"/href=".\1"/g;\
,)
all: md org rst adoc dot
md: $(MD_HTML) $(MD_PDF) css lib img dot
org: $(ORG_HTML) $(ORG_PDF) css lib img dot
rst: $(RST_HTML) $(RST_PDF) css lib img dot
adoc: $(ADOC_HTML) $(ADOC_PDF) css lib img dot
dot: $(DOT_SVG)
%.md.html: %.md $(CSS)
mkdir -p $(dir $(OUT)/$(dir $@))
pandoc \
--from=markdown \
--to=html5+smart \
--defaults=defaults.yaml \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .md,.yaml,$<) && echo 1),--defaults=$(subst .md,.yaml,$<),) \
-V basename=$(shell basename $< .md) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_HTML) \
--katex=$(subst %,,$(patsubst %,../,$(subst /,%,$(subst ./,,$(dir $@)))))$(OUT_LIB)/ \
$(foreach css,$(CSS),$\
--css $(subst %,,$(patsubst %,../,$(subst /,%,$(subst ./,,$(dir $@)))))$(OUT_CSS)/$(notdir $(css))) \
$< | sed '$(LINK_REGEX)' > $(OUT)/$(patsubst %.md,%.html,$<)
%.org.html: %.org $(CSS)
mkdir -p $(dir $(OUT)/$(dir $@))
pandoc \
--from=org+citations \
--to=html5+smart \
--defaults=$(if $(shell test -e $(shell basename $< .org).yaml),$(shell basename $< .org).yaml,defaults.yaml) \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .org,.yaml,$<) && echo 1),--defaults=$(subst .org,.yaml,$<),) \
-V basename=$(shell basename $< .org) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_HTML) \
--katex=$(subst %,,$(patsubst %,../,$(subst /,%,$(subst ./,,$(dir $@)))))$(OUT_LIB)/ \
$(foreach css,$(CSS),--css $(subst %,,$(patsubst %,../,$(subst /,%,$(subst ./,,$(dir $@)))))$(OUT_CSS)/$(notdir $(css))) \
$< | sed '$(LINK_REGEX)' > $(OUT)/$(patsubst %.org,%.html,$<)
%.rst.html: %.rst $(CSS)
mkdir -p $(dir $(OUT)/$(dir $@))
pandoc \
--from=rst \
--to=html5+smart \
--defaults=$(if $(shell test -e $(shell basename $< .rst).yaml),$(shell basename $< .rst).yaml,defaults.yaml) \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .rst,.yaml,$<) && echo 1),--defaults=$(subst .rst,.yaml,$<),) \
-V basename=$(shell basename $< .rst) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_HTML) \
--katex=$(subst %,,$(patsubst %,../,$(subst /,%,$(subst ./,,$(dir $@)))))$(OUT_LIB)/ \
$(foreach css,$(CSS),--css $(subst %,,$(patsubst %,../,$(subst /,%,$(subst ./,,$(dir $@)))))$(OUT_CSS)/$(notdir $(css))) \
$< | sed '$(LINK_REGEX)' > $(OUT)/$(patsubst %.rst,%.html,$<)
%.adoc.html: %.adoc $(CSS)
mkdir -p $(dir $(OUT)/$(dir $@))
asciidoctor -v -b docbook5 -o - $< \
| pandoc \
--from=docbook \
--to=html5+smart \
--defaults=$(if $(shell test -e $(shell basename $< .adoc).yaml),$(shell basename $< .adoc).yaml,defaults.yaml) \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .adoc,.yaml,$<) && echo 1),--defaults=$(subst .adoc,.yaml,$<),) \
-V basename=$(shell basename $< .adoc) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_HTML) \
--katex=$(subst %,,$(patsubst %,../,$(subst /,%,$(subst ./,,$(dir $@)))))$(OUT_LIB)/ \
$(foreach css,$(CSS),--css $(subst %,,$(patsubst %,../,$(subst /,%,$(subst ./,,$(dir $@)))))$(OUT_CSS)/$(notdir $(css))) \
| sed '$(LINK_REGEX)' > $(OUT)/$(patsubst %.adoc,%.html,$<)
%.md.pdf: %.md img dot
mkdir -p $(dir $(OUT)/$(dir $@))
pandoc \
--from=markdown \
--to=pdf \
--defaults=defaults.yaml \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .md,.yaml,$<) && echo 1),--defaults=$(subst .md,.yaml,$<),) \
--resource-path=$(dir $@):$(dir $(OUT)/$(dir $@)) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_PDF) \
-o $(OUT)/$(patsubst %.md,%.pdf,$<) \
$<
%.org.pdf: %.org img dot
mkdir -p $(dir $(OUT)/$(dir $@))
pandoc \
--from=org+citations \
--to=pdf \
--defaults=$(if $(shell test -e $(shell basename $< .org).yaml),$(shell basename $< .org).yaml,defaults.yaml) \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .org,.yaml,$<) && echo 1),--defaults=$(subst .org,.yaml,$<),) \
--resource-path=$(dir $@):$(dir $(OUT)/$(dir $@)) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_PDF) \
-o $(OUT)/$(patsubst %.org,%.pdf,$<) \
$<
%.rst.pdf: %.rst img dot
mkdir -p $(dir $(OUT)/$(dir $@))
pandoc \
--from=rst \
--to=pdf \
--defaults=$(if $(shell test -e $(shell basename $< .rst).yaml),$(shell basename $< .rst).yaml,defaults.yaml) \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .rst,.yaml,$<) && echo 1),--defaults=$(subst .rst,.yaml,$<),) \
--resource-path=$(dir $@):$(dir $(OUT)/$(dir $@)) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_PDF) \
-o $(OUT)/$(patsubst %.rst,%.pdf,$<) \
$<
%.adoc.pdf: %.adoc img dot
mkdir -p $(dir $(OUT)/$(dir $@))
asciidoctor -v -b docbook5 -o - $< \
| pandoc \
--from=docbook \
--to=pdf \
--defaults=$(if $(shell test -e $(shell basename $< .adoc).yaml),$(shell basename $< .adoc).yaml,defaults.yaml) \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .adoc,.yaml,$<) && echo 1),--defaults=$(subst .adoc,.yaml,$<),) \
--resource-path=$(dir $@):$(dir $(OUT)/$(dir $@)) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_PDF) \
-o $(OUT)/$(patsubst %.adoc,%.pdf,$<)
%.md.tex: %.md
mkdir -p $(dir $(OUT)/$(dir $@))
pandoc \
--from=markdown \
--to=latex \
--defaults=defaults.yaml \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .md,.yaml,$<) && echo 1),--defaults=$(subst .md,.yaml,$<),) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_PDF) \
-o $(OUT)/$(patsubst %.md,%.tex,$<) \
$<
%.org.tex: %.org
mkdir -p $(dir $(OUT)/$(dir $@))
pandoc \
--from=org+citations \
--to=latex \
--defaults=$(if $(shell test -e $(shell basename $< .org).yaml),$(shell basename $< .org).yaml,defaults.yaml) \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .org,.yaml,$<) && echo 1),--defaults=$(subst .org,.yaml,$<),) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_PDF) \
-o $(OUT)/$(patsubst %.org,%.tex,$<) \
$<
%.rst.tex: %.rst
mkdir -p $(dir $(OUT)/$(dir $@))
pandoc \
--from=rst \
--to=latex \
--defaults=$(if $(shell test -e $(shell basename $< .rst).yaml),$(shell basename $< .rst).yaml,defaults.yaml) \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .rst,.yaml,$<) && echo 1),--defaults=$(subst .rst,.yaml,$<),) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_PDF) \
-o $(OUT)/$(patsubst %.rst,%.tex,$<) \
$<
%.adoc.tex: %.adoc
mkdir -p $(dir $(OUT)/$(dir $@))
asciidoctor -v -b docbook5 -o - $< \
| pandoc \
--from=docbook \
--to=latex \
--defaults=$(if $(shell test -e $(shell basename $< .adoc).yaml),$(shell basename $< .adoc).yaml,defaults.yaml) \
$(if $(shell test -e $(shell dirname $<)/defaults.yaml && echo 1),--defaults=$(shell dirname $<)/defaults.yaml,) \
$(if $(shell test -e $(subst .adoc,.yaml,$<) && echo 1),--defaults=$(subst .adoc,.yaml,$<),) \
$(PANDOC_OPTS) \
$(PANDOC_OPTS_PDF) \
-o $(OUT)/$(patsubst %.adoc,%.tex,$<)
%.svg: %.dot
mkdir -p $(dir $(OUT)/$(dir $@))
neato -Tsvg $< > $(OUT)/$@
css: $(OUT)/$(OUT_CSS)
lib: $(OUT)/$(OUT_LIB)
img: $(OUT)/$(IMG)
$(OUT)/$(OUT_CSS): $(CSS) $(CSS_X)
mkdir -p $(OUT)/$(OUT_CSS)
cp -a $(CSS) $(CSS_X) $(OUT)/$(OUT_CSS)
$(OUT)/$(OUT_LIB):
mkdir -p $(OUT)/$(OUT_LIB)
wget -cP $(OUT)/$(OUT_LIB) $(KATEX_URL)/katex.min.js
wget -cP $(OUT)/$(OUT_LIB) $(KATEX_URL)/katex.min.css
wget -cP $(OUT)/$(OUT_LIB)/contrib $(KATEX_URL)/contrib/auto-render.min.js
$(OUT)/$(IMG):
mkdir -p $(OUT)
test -e $(IMG) && cp -a $(IMG) $(OUT)/ || true
clean:
rm -rf $(OUT)
.PHONY: clean
.PHONY: $(OUT)/$(OUT_CSS)
.PHONY: $(OUT)/$(IMG)