-
Notifications
You must be signed in to change notification settings - Fork 10
/
topic.mk
131 lines (105 loc) · 3.78 KB
/
topic.mk
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
# Set the site base output directory. (OUT_DIR is usually set by the master Makefile).
ifndef OUT_DIR
OUT_DIR = /Users/jo/Sites/rcloud_upload
endif
# Path from the output HTML file to the site root.
# Most topics are cotained in folders in the root of the site so
# the path to the root is simply '..'.
ifndef BASEPATH
BASEPATH = ..
endif
# Get the name of the folder containing this Makefile.
ifndef FOLDER
FOLDER = $(notdir $(CURDIR))
endif
ifndef BASESRC
BASESRC = ..
endif
# Set the output directory for this topic.
ifndef DSTDIR
DSTDIR = $(OUT_DIR)
endif
# Helpfull abreviations.
HTML = $(BASESRC)/html
EMPTY_PD = $(BASESRC)/empty.pd
SRC_TYPE = markdown
BODY_FN = body.html
# Form the header/footer template souce and destination names.
GEN_NAMES = head body_top body_bottom
GEN_FNS = $(foreach name,$(GEN_NAMES),$(name).html)
GEN_TMPLS = $(foreach name,$(GEN_NAMES),$(HTML)/$(name)_template.html)
# The index.html is dependent on the header and footer template files
# DEPEND = $(HTML)/head_template.html $(HTML)/body_top_template.html $(HTML)/body_bottom_template.html
DEPEND = $(GEN_TMPLS)
# If a local file named 'template.html5' exists then use it
# as the template for building index.html
TMPL_FN =template.html5
ifeq ($(strip $(wildcard $(TMPL_FN))),)
TMPL_FN = $(HTML)/template.html5
endif
DEPEND += $(TMPL_FN)
# If the local markdown file does not exist
# then use dummy.pd
PD_FN = index.pd
ifeq ($(strip $(wildcard $(PD_FN))),)
PD_FN = $(EMPTY_PD)
DEPEND += $(BODY_FN)
ifeq ($(strip $(wildcard $(BODY_FN))),)
$(warn No index.pd or body.html was specified for the topic $(FOLDER).)
endif
endif
DEPEND += $(PD_FN)
# If the local YAML file does not exist then ignore it
YAML_FN = index.yaml
ifeq ($(strip $(wildcard $(YAML_FN))),)
YAML_FN =
endif
DEPEND += $(YAML_FN)
all : $(DSTDIR)/index.html $(DSTDIR)/index.css
$(DSTDIR)/index.html : $(DEPEND) $(GEN_FNS)
mkdir -p $(DSTDIR)
$(BASESRC)/make_template.sh $(BASESRC)
pandoc \
--to=html5 \
--from=$(SRC_TYPE) \
--template=local.template \
--css=index.css \
--variable=basepath:$(BASEPATH) \
--variable=container:$(CONTAINER) \
--variable=inner-wrapper:$(INNER_WRAPPER) \
--include-in-header=head.html \
--include-before-body=body_top.html \
--include-after-body=body_bottom.html \
$(PANDOC_OPTS) \
-o $(DSTDIR)/index.html $(PD_FN) $(YAML_FN)
# Copy the local css file to the destination directory.
$(DSTDIR)/index.css : index.css
cp index.css $(DSTDIR)/index.css
#
# Use $(BASESRC)/hmtl/*_template.html to generate a include
# files with the CSS,Javscript and href refrences pointing to the correct
# location.
#
# The globally referenced CSS and Javascript files are in folders in
# the site's root directory (css and js). The references to these
# files contained in the <style> and <script> tags of the client HTML
# files will therefore vary depending on their depth in the tree.
# 'href' attributes in the global page headers have a similar problem.
# This means the the references must be generated according to the
# location of the HTML files. We solve this by using a pandoc template
# file containing the global references (html/head_template.html)
# and filling in the path to the 'css' and 'js' folders using a
# variable. The resulting output, head.html, is then inserted into
# the final output file by using the --include-in-header pandoc
# option.
$(GEN_FNS) : %.html : $(HTML)/%_template.html
pandoc --template=$< --variable=basepath:$(BASEPATH) --variable=bootstrap:$(BOOTSTRAP) $(TMPL_PANDOC_OPTS) -o $@ $(EMPTY_PD)
# Delete all files generated by this Makefile
clean-all : clean
rm -f $(DSTDIR)/index.html
ifneq ($(strip $(realpath $(DSTDIR)/index.css)),index.css)
rm -f $(DSTDIR)/index.css local.template
endif
clean :
rm -f $(GEN_FNS) local.template
.PHONY : all clean clean-all $(PHONY_TARGETS)