-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathMakefile
260 lines (194 loc) · 6.13 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
.PHONY: blog podcast comp gz br remove clean webp avif
.SUFFIXES: .html .md .amp .amp.html .webp .avif .png .jpeg .gif
# NODE := $(DEV)/jxck.io/node_modules/.bin/bun
NODE := $(HOME)/.local/share/mise/installs/node/latest/bin/node
build:
make fmt
cd .src && $(NODE) build.js build
make comp
compile:
$(NODE) -v
cd .src && $(NODE) build.js build
preview:
cd .src && $(NODE) build.js preview
draft:
cd .src && $(NODE) build.js draft
fmt:
.src/markdown/formatter.js blog.jxck.io/entries/**/*.md
prettier -w mozaic.fm/episodes/**/*.md
install:
npm install
$(DOTFILES)/install/install-avif.sh
$(DOTFILES)/install/install-brotli.sh
$(DOTFILES)/install/install-h2o.sh
$(DOTFILES)/install/install-webp.sh
$(DOTFILES)/install/install-guetzli.sh
update:
ncu -u
systemd-list:
@systemctl list-unit-files | grep $(foreach service, $(notdir $(wildcard ./.systemd/*)), -e '^$(service)')
systemd-status:
$(foreach service, $(notdir $(wildcard ./.systemd/*)), systemctl status $(service))
cron:
sudo crontab -u root .crontab/*
sudo crontab -u root -l
## optimize all image
image:
which pngquant
which optipng
which jpeg-recompress
which mozjpeg
which guetzli
which gifsicle
which avif
which ffmpeg
which cwebp gif2webp
$(MAKE) png
$(MAKE) jpeg
$(MAKE) gif
$(MAKE) webp
$(MAKE) avif
##########################
# Compression
##########################
# 探索は www/blog/mozaic のみ
# 対象外ファイルを除き brotli で圧縮する (zopfli/gz は h2o 側でやることにした)
WWW = $(shell selects path from "./www.jxck.io/**/*" where "file?" "==" "true" and extname "!~" ".gz|.br|.sb|.png|.jpeg|.gif|.webp|.avif|.mp4|.webm|.rb|.md|.txt|.woff2|.sh|.cgi" order by path desc)
BLO = $(shell selects path from "./blog.jxck.io/**/*" where "file?" "==" "true" and extname "!~" ".gz|.br|.sb|.png|.jpeg|.gif|.webp|.avif|.mp4|.webm|.rb|.md|.txt|.woff2|.sh|.cgi" and path "!~" "drafts" and path "!~" "tags" order by path desc)
MOZ = $(shell selects path from "./mozaic.fm/**/*" where "file?" "==" "true" and extname "!~" ".gz|.br|.sb|.png|.jpeg|.gif|.webp|.avif|.mp4|.webm|.rb|.md|.txt|.woff2|.sh|.cgi" order by path desc)
TARGET = $(WWW) $(BLO) $(MOZ)
ENTRIES = $(shell selects path from "./blog.jxck.io/entries/**/*.html")
BR = $(addsuffix .br, $(TARGET))
SB = $(addsuffix .sb, $(ENTRIES))
#HASH_TARGET = $(shell etag.rb $(filter-out %.html, $(TARGET)))
#COMP_TARGET = $(addsuffix .br, $(HASH_TARGET) $(filter %.html, $(TARGET)))
# .js => .xxxx.js
#$(HASH_TARGET): $(TARGET)
# cp $(abspath $<) $(abspath $@)
# .xxx.js => .xxx.js.br
#$(COMP_TARGET): $(HASH_TARGET)
%.br: %
brotli -q 11 -f $<
# touch -r $< $@
%.sb: %
brotli -q 11 -f --dictionary=$(wildcard ./blog.jxck.io/dictionary/*dict) --suffix=.sb $<
# touch -r $< $@
# 対象ファイルを圧縮
comp: $(BR) $(SB)
# 圧縮を削除
clean:
@rm -fv $(BR)
@rm -fv $(SB)
# ビルド結果(HTML)も削除
remove:
@rm -fv $(BHTML)
@rm -fv $(BHTML:.html=.amp.html)
@rm -fv $(PHTML)
##########################
# Build Markdown
##########################
# .md
BMD = $(wildcard ./blog.jxck.io/entries/**/*.md)
PMD = $(wildcard ./mozaic.fm/episodes/**/*.md)
# .html
BHTML = $(BMD:.md=.html)
PHTML = $(PMD:.md=.html)
# .md -> .html
# .md.html:
# $(MARK) $(if $(findstring blog.jxck.io, $*), --blog, --podcast) ./$*.md
##########################
# Optimize Image
##########################
## png
PNGQUANT := pngquant --force --skip-if-larger --speed 1 --strip --ext .png --verbose
OPTIPNG := optipng -o7
png:
find ./blog.jxck.io/entries/**/*.png \
| xargs -P$(shell core) -I{} sh -c '$(OPTIPNG) {}'
#| xargs -P$(shell core) -i{} sh -c '$(PNGQUANT) {}'
## jpeg
JPEGRECOMP := jpeg-recompress --strip
MOZJPEG := mozjpeg -optimize
GUETZLI := guetzli
jpeg:
find ./blog.jxck.io/entries/**/*.jpeg \
| xargs -P$(shell core) -I{} sh -c 'echo {} && $(GUETZLI) {} {}'
#| xargs -P$(shell core) -i{} sh -c 'echo {} && $(JPEGRECOMP) {} {}'
#| xargs -P$(shell core) -i{} sh -c '$(MOZJPEG) -outfile {} {}'
## gif
GIFSICLE := gifsicle --optimize=3 --colors 256 -v
gif:
find ./blog.jxck.io/entries/**/*.gif \
| xargs -P$(shell core) -I{} sh -c '$(GIFSICLE) {} -o {}'
PNG = $(wildcard ./blog.jxck.io/entries/**/*.png)
JPG = $(wildcard ./blog.jxck.io/entries/**/*.jpeg)
GIF = $(wildcard ./blog.jxck.io/entries/**/*.gif)
## webp
CWEBP = cwebp -q 40 -quiet -m 6
GWEBP = gif2webp -q 40 -quiet -m 6
WEBP = $(PNG:.png=.webp)
WEBP += $(JPG:.jpeg=.webp)
WEBP += $(GIF:.gif=.webp)
.png.webp:
$(CWEBP) $*.png -o $*.webp
touch -r $< $@
.jpeg.webp:
$(CWEBP) $*.jpeg -o $*.webp
touch -r $< $@
.gif.webp:
$(GWEBP) $*.gif -o $*.webp
touch -r $< $@
webp: $(WEBP)
## avif
CAVIF = npx avif --speed 0 --quality 40
AVIF = $(PNG:.png=.avif)
AVIF += $(JPG:.jpeg=.avif)
AVIF += $(GIF:.gif=.avif)
.png.avif:
$(CAVIF) --input $*.png
touch -r $< $@
.jpeg.avif:
$(CAVIF) --input $*.jpeg
touch -r $< $@
.gif.avif:
ffmpeg -i $*.gif -pix_fmt yuv420p -f yuv4mpegpipe - | avifenc --stdin --fps 15 $*.avif
touch -r $< $@
avif: $(AVIF)
##########################
# formatter
##########################
space:
selects path from './blog.jxck.io/entries/**/*' where extname '==' '.md' | xargs -L 1 spacer
selects path from './mozaic.fm/episodes/**/*' where extname '==' '.md' | xargs -L 1 spacer
singler:
selects path from './blog.jxck.io/entries/**/*' where extname '==' '.md' | xargs -L 1 singler
selects path from './mozaic.fm/episodes/**/*' where extname '==' '.md' | xargs -L 1 singler
format:
selects path from './blog.jxck.io/entries/**/*' where extname '==' '.md' | xargs -L 1 format.rb
selects path from './mozaic.fm/episodes/**/*' where extname '==' '.md' | xargs -L 1 format.rb
##########################
# h2o
##########################
start:
sudo systemctl start h2o
stop:
sudo systemctl stop h2o
status:
sudo systemctl status h2o
kill:
sudo systemctl kill h2o
restart:
sudo systemctl restart h2o
reload:
sudo $(DOTFILES)/local/h2o/bin/h2o -t -c h2o.conf | cat
sudo systemctl reload h2o
test:
sudo $(DOTFILES)/local/h2o/bin/h2o -t -c h2o.conf | cat
## h2o local
_start:
sudo $(DOTFILES)/local/h2o/bin/h2o -m daemon -c h2o.conf
_stop:
sudo kill -TERM `cat ./.pid/h2o.pid`
_restart:
$(MAKE) _stop
$(MAKE) _start