-
Notifications
You must be signed in to change notification settings - Fork 9
/
makefile
150 lines (120 loc) · 5.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
SHELL = /bin/bash
### Type 'make' at the prompt to see a list of available tasks.
# --- Variables used by rules ---
core-files := pollen.rkt \
index.ptree \
util-date.rkt \
pollen-local/polytag.rkt \
pollen-local/common-helpers.rkt \
pollen-local/publication-vals.rkt
posts-sourcefiles := $(wildcard posts/*.poly.pm)
posts-html := $(patsubst %.poly.pm,%.html,$(posts-sourcefiles))
posts-pdf := $(patsubst %.poly.pm,%.pdf,$(posts-sourcefiles))
# I want to show off my Pollen source files, so I name them .pollen.html
posts-sourcelistings := $(patsubst %.poly.pm,%.pollen.html,$(posts-sourcefiles))
other-sourcefiles := books.html.pm about.html.pm
other-html := $(patsubst %.html.pm,%.html,$(other-sourcefiles))
other-sourcelistings := $(patsubst %.html.pm,%.pollen.html,$(other-sourcefiles))
# --- Rules ---
all: last_html.rebuild $(posts-html) $(posts-sourcelistings) $(other-html) $(other-sourcelistings) index.html feed.xml topics.html
all: ## Update all web content (not PDFs)
# Certain files affect all HTML output files. If these change, I want to do a complete rebuild
# of all posts. Rendering the whole ptree is somewhat faster than rendering each post separately.
#
# To ensure Pollen doesn't rely on its cache for these rebuilds, we need to touch pollen.rkt.
# But we save its timestamp first and restore it afterwards; otherwise we'd have the side effect
# of triggering the rule for last_pdf.rebuild also, even if pollen.rkt hadn't actualy been changed.
last_html.rebuild: $(core-files) template.html.p util-template.rkt pollen-local/tags-html.rkt
touch -r pollen.rkt _save_timestamp
touch pollen.rkt
raco pollen setup -p posts/
raco pollen render -p -t html posts/*.poly.pm
tidy -quiet -modify -indent --wrap 0 --tidy-mark no --drop-empty-elements no posts/*.html || true
touch -r _save_timestamp pollen.rkt; rm _save_timestamp
touch last_html.rebuild
# If the above rule was triggered, all the posts-html files will already have been re-rendered.
# (That rule comes before this one in the list of dependencies for "all")
# But if not, any individual files that have been edited will get re-rendered.
$(posts-html): %.html: %.poly.pm
raco pollen render -t html $<
tidy -quiet -modify -indent --wrap 0 --tidy-mark no --drop-empty-elements no $@ || true
$(posts-sourcelistings): util/make-html-source.sh
$(posts-sourcelistings): %.pollen.html: %.poly.pm
util/make-html-source.sh $< > $@
tidy -quiet -modify -indent --wrap 0 --tidy-mark no --drop-empty-elements no $@ || true
pdfs: ## Update PDF files
pdfs: last_pdf.rebuild $(posts-pdf)
# Similar to HTML, first re-render all the PDFs if necessary...
last_pdf.rebuild: $(core-files) template.pdf.p util-template.rkt pollen-local/tags-pdf.rkt
touch -r pollen.rkt _save_timestamp
touch pollen.rkt
raco pollen setup -p posts/
raco pollen render -p -t pdf posts/*.poly.pm
touch -r _save_timestamp pollen.rkt; rm _save_timestamp
touch last_pdf.rebuild
# ...then, if a complete re-render wasn't necessary, render any individual PDFs that need it.
$(posts-pdf): %.pdf: %.poly.pm
raco pollen render -t pdf $<
feed.xml: $(core-files) $(posts-sourcefiles) feed.xml.pp util-template.rkt pollen-local/tags-html.rkt
touch feed.xml.pp
raco pollen render feed.xml.pp
index.html: $(core-files) $(posts-sourcefiles)
index.html: index.html.pp util-template.rkt pollen-local/tags-html.rkt
touch index.html.pp
raco pollen render index.html
tidy -quiet -modify -indent --wrap 0 --tidy-mark no --drop-empty-elements no index.html || true
$(other-html): %.html: %.html.pm
raco pollen render $@
tidy -quiet -modify -indent --wrap 0 --tidy-mark no --drop-empty-elements no $@ || true
$(other-sourcelistings): util/make-html-source.sh
$(other-sourcelistings): %.pollen.html: %.html.pm
util/make-html-source.sh $< > $@
topics.html: topics.html.pp $(core-fils) $(posts-sourcefiles) pollen-local/tags-html.rkt
touch topics.html.pp
raco pollen render topics.html.pp
tidy -quiet -modify -indent --wrap 0 --tidy-mark no --drop-empty-elements no topics.html || true
# --- Additional project tasks ---
.PHONY: all pdfs publish spritz zap help
# Doing ‘make publish’ automatically upload everything except the Pollen source
# files to the public web server. The NOTEPAD_SRV is defined as an environment
# variable for security reasons (never put credentials in a script!)
# Make sure yours is of the form ‘username@serverdomain.com:public_html/’
# See also the docs for ‘raco pollen publish’:
# http://pkg-build.racket-lang.org/doc/pollen/raco-pollen.html
publish: ## Rsync the website to the public web server (does not rebuild site first)
rm -rf latex-tmp
raco pollen publish
rsync -av ~/Desktop/publish/ -e 'ssh -p $(WEB_SRV_PORT)' $(NOTEPAD_SRV) \
--delete \
--exclude=projects \
--exclude=.git \
--exclude=drafts \
--exclude=pollen-local \
--exclude='*.sqlite' \
--exclude='*.ltx' \
--exclude='*.swp' \
--exclude='*.rebuild' \
--exclude=.DS_Store \
--exclude=.gitignore \
--exclude='template*.*' \
--exclude=makefile \
--exclude=util \
--exclude='posts/img/originals'
rm -rf ~/Desktop/publish
# ‘make spritz’ just cleans up temporary LaTeX files and clears the Pollen cache;
# ‘make zap’ deletes all output files as well.
spritz: ## Just cleans up LaTeX working folders and Pollen cache
-rm -rf latex-tmp
raco pollen reset
zap: spritz ## Does a spritz and also deletes all HTML and PDF output
-rm posts/*.html posts/*.pdf
-rm feed.xml
-rm *.html *.pdf
-rm -f notepad.sqlite
raco pollen reset
post: ## Quickly start a new post from template
racket util/newpost.rkt
# Self-documenting makefile (http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html)
help: ## Displays this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help