-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
286 lines (234 loc) · 8.24 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
SITE=davidjenei.com
#################################################################################
# HTML PAGES
#################################################################################
INDEX_HTML=docs/index.html
NOTES_HTML=docs/notes.html
BLOG_HTML=docs/blog.html
RESUME_HTML=docs/resume.html
RESUME_PRIVATE=docs/resume-private.html
RESUME_PUBLIC=docs/resume-public.html
HTMLS=$(INDEX_HTML) $(RESUME_HTML) $(RESUME_PRIVATE) $(RESUME_PUBLIC) \
$(BLOG_HTML) docs/radar.html docs/notes.html docs/tags.html
POSTS != ls -t blog/*md
POST_HTMLS=$(POSTS:blog/%.md=docs/blog/%.html)
NOTES != ls notes/*.md
NOTES_HTMLS=$(NOTES:notes/%.md=docs/notes/%.html)
TAGS != grep -oPh '^tags:\s*\K.*' notes/*.md \
| tr -d '\#' \
| tr ' ' '\n' \
| sort -u
TAG_HTMLS=$(TAGS:%=docs/tags/tag_%.html)
DOC_DIRS=docs/tags docs/notes docs/blog
STYLE=docs/style.css
.PHONY: all
all : $(HTMLS) $(POST_HTMLS) $(NOTES_HTMLS) $(TAG_HTMLS)
#################################################################################
# MARKDOWN TO HTML
#################################################################################
LOWDOWN_ARGS= -Thtml \
--html-no-skiphtml \
--html-no-escapehtml \
--html-no-owasp \
--html-no-num-ent
$(DOC_DIRS):
@mkdir -p $@
docs/%.pre: %.md | $(DOC_DIRS)
@cat $< | sed 's/\.md/.html/g' | lowdown -o $@ $(LOWDOWN_ARGS)
#################################################################################
# BUILD TAGS
#################################################################################
RECENT != ls -t notes/*md | head -n 5
tagsdir:
@mkdir tags
# Use variables instead of command substitution, because parameter expansion
# gives more readable code when dealing with missing metadata
READ_METADATA = \
TITLE=`grep -oP "^title: \K.*" $${file} || echo $${file}`; \
DESC=`grep -oP "^description: \K.*" $${file}`; \
MATURITY=`grep -oP "^maturity: \K.*" $${file}`; \
TAGS=`grep -oP "^tags: \K.*" $${file}`; \
WORDS=`cat $${file} | wc -w`; \
DATE=`stat --format="%y" $${file} | cut -d' ' -f1`;
PRINT_METADATA = \
$(READ_METADATA) \
\
printf "[%s](../$${file}) " \
"$${TITLE}" >> $@; \
echo >> $@; \
printf "*%s%s%s%s*" \
"$${DESC:+$$DESC · }" \
"$${MATURITY:+$$MATURITY · }" \
"$${WORDS:+$$WORDS words · }" \
"$${DATE}" \
>> $@ ; \
\
for _tag in $$TAGS; do \
TAG=$$(echo $${_tag} | tr -d '\#'); \
echo -n " · [$${_tag}](../tags/tag_$${TAG}.md)" >> $@; \
done; \
echo >> $@; \
echo >> $@;
PRINT_METADATA_SHORT = \
$(READ_METADATA) \
\
printf "* [%s](./$${file}) · " \
"$${TITLE}" >> $@; \
\
printf "*%s%s*" \
"$${MATURITY:+$$MATURITY · }" \
"$${WORDS:+$$WORDS words}" \
>> $@ ; \
\
for _tag in $$TAGS; do \
TAG=$$(echo $${_tag} | tr -d '\#'); \
echo -n " · [$${_tag}](../tags/tag_$${TAG}.md)" >> $@; \
done; \
echo >> $@;
tags/tag_%.md: | tagsdir
@echo "title: #$*" > $@
@echo >> $@
@echo "# Notes tagged with #$* { .tag }" >> $@
@echo >> $@
@printf "tags/tag_$*.md: " > deps/tags/tag_$*.d
@for file in $$(grep -l "^tags:.*#$*\b" notes/*.md); do \
$(PRINT_METADATA) \
printf "$${file} " >> deps/tags/tag_$*.d; \
done
TAG_LIST=$(wildcard tags/*.md)
TAG_DEPS=$(TAG_LIST:%.md=deps/%.d)
-include $(TAG_DEPS)
tags.md: $(NOTES)
@echo > $@
@for tag in $(TAGS); do \
echo -n "* [$${tag}](tags/tag_$${tag}.md)\t" >> $@; \
grep -o "^tags:.*#$${tag}\b" notes/*.md | wc -l >> $@; \
done
posts.md: $(POSTS)
@echo > $@
@for file in $(POSTS); do \
$(PRINT_METADATA) \
done
recent.md: $(RECENT)
@echo "## Recent updates { .recent }" > $@
@echo >> $@
@for file in $(RECENT); do \
$(PRINT_METADATA_SHORT) \
done
.PHONY:
gen-tags: tags.md $(patsubst %,tags/tag_%.md,$(TAGS))
#################################################################################
# BUILD HTML
#################################################################################
REL_PATH = realpath --relative-to=$$(dirname $@)
GET_TITLE = grep -oP "^title:\s*\K.*" $${file} 2>/dev/null
define html_envelope
@file="$(1)"; \
printf "$(HEAD_HTML)" `$(REL_PATH) $(STYLE)` "`$(GET_TITLE)`" > $@
@test -z $(RAW) && printf "$(NAV_HTML)" >> $@ || true
@echo "$(PREPEND)" >> $@
@cat $2 >> $@
@test -z $(RAW) && printf "$(FOOTER_HTML)" `$(REL_PATH) $(INDEX_HTML)` \
`$(REL_PATH) $(BLOG_HTML)` \
`$(REL_PATH) $(NOTES_HTML)` \
`$(REL_PATH) $(RESUME_HTML)` \
>> $@ || true
@echo "$(BODY_END_HTML)" >> $@
@tidy --tidy-mark no -q -i -m $@
@echo "$@ generated"
endef
HEAD_HTML = \
<!doctype html> \
<html lang="en" id="top"> \
<head> \
<meta charset="utf-8"> \
<meta name="viewport" content="width=device-width,initial-scale=1"> \
<link rel="icon" href="data:,"> \
<link rel="stylesheet" href="%s"> \
<title>%s - $(SITE)</title> \
</head> \
<body>
NAV_HTML = \
<nav> \
<a href="\#menu">Menu ↓</a> \
</nav> \
BODY_END_HTML = \
</body> \
</html>
FOOTER_HTML = \
<footer> \
<hr> \
<h3 id="menu">Navigation</h3> \
<ul> \
<li> <a href="%s">About</a> </li> \
<li> <a href="%s">Posts</a> </li> \
<li> <a href="%s">Notes</a> </li> \
<li> <a href="%s">Resume</a> </li> \
<li> <a href="\#top">Back to top ↑</a> \
</ul> \
<small> \
The content for this site is \
<a href= \
"http://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>. \
<br> \
The <a href="https://github.com/davidjenei/davidjenei.com">code for this site</a> is \
<a href="https://github.com/davidjenei/davidjenei.com/blob/main/LICENSE">MIT</a>. \
<br> \
Made with markdown, \
<a href="https://kristaps.bsd.lv/lowdown/">lowdown</a> \
and \
<a href="https://www.gnu.org/software/make/">make</a>. \
Inspired by <a href="https://git.sr.ht/~bt/barf">barf</a>. \
</small> \
</footer>
BIO_HTML = \
<div id="bio"> \
<div> \
<h1>Dávid Jenei</h1> \
$(TITLE_HTML) \
Budapest, HU • \
<a href="mailto:[email protected]">[email protected]</a> \
$(PHONE_HTML) \
</div> \
<div> \
<img src="./profile.jpg" alt="profile" /> \
</div> \
</div>
docs/blog.html: docs/blog.pre docs/posts.pre
docs/%.html: docs/%.pre
$(call html_envelope, $*.md, $^ )
docs/notes.html: docs/notes.pre docs/tags.pre docs/recent.pre
$(RESUME_HTML): PREPEND=$(BIO_HTML)
#################################################################################
# RESUMES
#################################################################################
docs/resume-%.html: PREPEND=$(BIO_HTML)
docs/resume-%.html: RAW=yes
docs/resume-%.html: TITLE_HTML=<p>Embedded Software Engineer</p>
docs/resume-%.html: docs/resume.pre
$(call html_envelope, resume.md, $^)
docs/resume-private.html: PHONE_HTML=• <a href="tel:${PHONE}">${PHONE}</a>
#################################################################################
# TASKS
#################################################################################
.PHONY: clean
clean:
- @rm $(HTMLS) $(POST_HTMLS) $(NOTES_HTMLS) $(TAG_HTMLS)
- rm -r $(DOC_DIRS)
.PHONY: publish
publish: all
rsync -azh docs/ ~/static/davidjenei.com
.PHONY: publish-remote
publish-remote: all
rsync -azh docs/ $(SITE):~/static/davidjenei.com
.PHONY: help
help:
@echo "usage: make [OPTIONS] <target>"
@echo " Options:"
@echo " > PHONE Set phone number for resume"
@echo "Targets:"
@echo " all: Build /notes, /blog and the index pages"
@echo " publish: Upload html docs to the server"
@echo " gen-tags: Create tag pages"
@echo " $(RESUME_PRIVATE): Build resume with phone number"
@echo " $(RESUME_PUBLIC): Build resume without phone number"