summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2022-06-20 16:58:31 +0200
committerVolpeon <git@volpeon.ink>2022-06-20 16:58:31 +0200
commit9020a9381ca281e521546af7d5780d7e2edf9dab (patch)
treeee30ba1b5bf5929574c05d90f7f799f1e15e0588
parentRemove card ellipsis (diff)
downloadvolpeon.ink-9020a9381ca281e521546af7d5780d7e2edf9dab.tar.gz
volpeon.ink-9020a9381ca281e521546af7d5780d7e2edf9dab.tar.bz2
volpeon.ink-9020a9381ca281e521546af7d5780d7e2edf9dab.zip
WIP: Hashing all static assets
-rw-r--r--Makefile copy215
1 files changed, 215 insertions, 0 deletions
diff --git a/Makefile copy b/Makefile copy
new file mode 100644
index 0000000..52d4dd8
--- /dev/null
+++ b/Makefile copy
@@ -0,0 +1,215 @@
1export DEPLOY_TARGET = vulpes@94.130.78.123:/srv/http/volpeon.ink/
2
3-include Env.mk
4
5#
6# FILE GROUPS
7#
8
9PANDOC_FILTERS := $(patsubst %,--lua-filter %,$(wildcard filters/*.lua))
10GLOBAL_METADATA := $(patsubst %,--metadata-file %,$(wildcard metadata/*.yaml))
11
12CONTENT_SRC := $(shell find content -type f -name "*.md")
13FEED_SRC := $(shell grep -l "^feed: *true$$" $(CONTENT_SRC))
14CONTENT_TEMPLATES_SRC := $(shell find templates -type f -name "*.html")
15FEED_TEMPLATES_SRC := $(shell find templates -type f -name "*.xml")
16CSS_SRC := $(shell find assets/css -type f -name "*.scss")
17
18CONTENT_META := $(patsubst content/%.md,.cache/meta/%.json,$(CONTENT_SRC))
19CONTENT_FILES := $(patsubst content/%.md,out/%.html,$(CONTENT_SRC))
20FEED_FILES := $(patsubst content/%.md,out/%.xml,$(FEED_SRC))
21FONT_FILES := $(patsubst assets/fonts/%.ttf,out/%.woff2,$(wildcard assets/fonts/*.ttf))
22CSS_FILES := $(patsubst assets/css/%.scss,out/%.css,$(wildcard assets/css/style.scss))
23STATIC_FILES := $(patsubst content/%,out/%,$(shell find content -type f ! -name "*.md"))
24STATIC_HASHED_FILES := $(filter out/%.css out/%.js out/%.svg out/%.woff2,$(STATIC_FILES))
25
26#
27# TARGETS
28#
29
30all: content_meta content_files feed_files font_files css_files static_files icons
31
32content_meta: $(CONTENT_META)
33content_files: $(CONTENT_FILES)
34feed_files: $(FEED_FILES)
35font_files: $(FONT_FILES)
36css_files: $(CSS_FILES)
37static_files: $(STATIC_FILES)
38
39#
40# RULES
41#
42
43.SECONDEXPANSION:
44
45namespace = $(patsubst %/index,%,$(patsubst %.json,%,$(patsubst $(2)%,%,$(1))))
46
47subpages = $(patsubst content/%.md,.cache/meta/%.json, \
48 $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \
49 $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md"))
50
51.cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) filters/*.lua scripts/subpages.lua scripts/subpages.jq scripts/metadata_tpl.json | .cache/meta
52 $(info [META] $< -> $@)
53
54 mkdir -p $(@D)
55 $(eval PAGES_FILES = $(filter .cache/meta/%.json,$^))
56 $(eval NAMESPACE = $(call namespace,$@,.cache/meta))
57 $(if $(PAGES_FILES),jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES) > "$@.pages",echo "{}" > "$@.pages")
58 pandoc \
59 -f markdown-citations-implicit_figures \
60 -t html5 \
61 --wrap preserve \
62 --no-highlight \
63 --template scripts/metadata_tpl.json \
64 --metadata namespace="$(NAMESPACE)" \
65 --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \
66 --metadata-file "$@.pages" \
67 $(PANDOC_FILTERS) \
68 -o "$@.meta" "$<"
69 pandoc \
70 -f markdown-citations-implicit_figures \
71 -t html5 \
72 --wrap preserve \
73 --lua-filter scripts/metadata_filter.lua \
74 --lua-filter scripts/subpages.lua \
75 $(GLOBAL_METADATA) \
76 --metadata-file "$@.meta" \
77 --metadata file_out="$@" \
78 $(PANDOC_FILTERS) \
79 -o "$@.content" "$<"
80 jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@"
81 rm "$@.pages"
82 rm "$@.meta"
83 rm "$@.content"
84
85.cache/hash.json: $(STATIC_HASHED_FILES) | .cache
86 echo "$^"
87 shell sha256sum "$^" | sed -r 's/([0-9a-f]+) +.*\/(.*)/"\2": "\1"/'
88
89out/%.html: content/%.md .cache/meta/%.json .cache/hash.json $(CONTENT_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua out/style.css | out
90 $(info [MARK] $< -> $@)
91
92 mkdir -p $(@D)
93 pandoc \
94 -f markdown-citations-implicit_figures \
95 -t html5 \
96 --wrap preserve \
97 --no-highlight \
98 --template templates/base.html \
99 --lua-filter scripts/metadata_filter.lua \
100 $(GLOBAL_METADATA) \
101 --metadata-file ".cache/hash.json" \
102 --metadata-file "$(filter .cache/meta/%.json,$^)" \
103 --metadata file_out="$@" \
104 $(PANDOC_FILTERS) \
105 -o "$@" "$<"
106
107out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml filters/*.lua scripts/metadata_filter.lua | out
108 $(info [FEED] $< -> $@)
109
110 mkdir -p $(@D)
111 pandoc \
112 -f markdown-citations-implicit_figures \
113 -t html5 \
114 --wrap preserve \
115 --no-highlight \
116 --template templates/feed.xml \
117 --lua-filter scripts/metadata_filter.lua \
118 $(GLOBAL_METADATA) \
119 --metadata-file "$(filter .cache/meta/%.json,$^)" \
120 --metadata file_out="$@" \
121 $(PANDOC_FILTERS) \
122 -o "$@" "$<"
123
124out/%/thumbnail.png: content/%/thumbnail.png | out
125 $(info [THMB] $< -> $@)
126
127 convert -thumbnail 550x280^ -gravity center -extent 550x280 "$<" png:- | pngquant -o "$@" -
128
129out/%/thumbnail.jpg: content/%/thumbnail.jpg | out
130 $(info [THMB] $< -> $@)
131
132 convert -thumbnail 550x280^ -gravity center -extent 550x280 "$<" ppm:- | cjpeg -quality 80 > "$@"
133
134out/%.woff2: assets/fonts/%.ttf assets/fonts/glyphs.txt | out
135 $(info [FONT] $< -> $@)
136
137 pyftsubset "$<" \
138 --text-file="assets/fonts/glyphs.txt" \
139 --layout-features+=ss09,dlig \
140 --flavor="woff2" \
141 --output-file="$@"
142
143out/%.css: assets/css/%.scss $(CSS_SRC) | out
144 $(info [SCSS] $< -> $@)
145
146 sass --load-path=node_modules "$<" | ./node_modules/.bin/postcss --use autoprefixer --no-map -o "$@"
147
148out/%: content/% | out
149 $(info [COPY] $< -> $@)
150
151 mkdir -p $(@D)
152 cp "$<" "$@"
153
154icons: | out
155 $(info [ICON] out/icons.svg)
156
157 node ./node_modules/iro-icons/scripts/create_sprite.js \
158 asterisk \
159 arrow-left \
160 arrow-right \
161 arrow-up-right \
162 shuffle \
163 envelope \
164 hash \
165 messages \
166 parallelogram \
167 globe \
168 image \
169 graph \
170 git-branch \
171 smile \
172 link \
173 x \
174 chevron-left \
175 chevron-right \
176 "out/icons.svg"
177
178.cache/hash: | .cache
179 mkdir -p .cache/hash
180
181.cache/meta: | .cache
182 mkdir -p .cache/meta
183
184.cache:
185 mkdir -p .cache
186
187out:
188 mkdir -p out
189
190#
191# UTILITIES
192#
193
194watch: all
195 while true; do \
196 inotifywait -qr -e modify -e create -e delete -e move assets content filters metadata scripts templates; \
197 $(MAKE); \
198 done
199
200serve: all
201 python -m http.server --bind 127.0.0.1 --directory out 8000
202
203dev: watch serve
204
205compress: all
206 pigz -R -k -9 -- `find out -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\)'`
207 brotli -k -- `find out -type f -iregex '.*\\.\\(css\\|js\\|json\\|html\\|xml\\|txt\\|svg\\|ico\\|woff\\)'`
208
209deploy: compress
210 rsync --progress --stats -rvz --delete out/ "$(DEPLOY_TARGET)"
211
212clean:
213 rm -rf out
214
215.PHONY: all watch serve dev deploy clean