summary refs log tree commit diff stats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile93
1 files changed, 93 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..0d658d4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,93 @@
+.SHELLFLAGS := -eu -o pipefail -c
+.ONESHELL:
+.DELETE_ON_ERROR:
+
+PREFIX ?= public
+
+md_files := $(shell fd . content --type=file -e md)
+brotli := @brotli --force --no-copy-stat
+gzip := @gzip --best --keep --force
+zstd := @zstd --force --no-pass-through -19 --quiet --stdout
+pr   := @printf "%4s %s\n"
+
+build: $(PREFIX)/index.html
+
+$(PREFIX)/index.html: config.toml $(md_files)
+	zola build --force --output-dir $(PREFIX)
+
+format: .formatstamp
+
+.formatstamp: $(PREFIX)/index.html
+	@echo "Formatting HTML..."
+	@prettier --write --parser html --print-width 200 "$(PREFIX)/**/*.html" > /dev/null
+	@touch .formatstamp
+
+clean:
+	rm -rf ./$(PREFIX)
+	rm -rf ./.*stamp
+
+to_compress := $(shell fd . $(PREFIX) --type=file -e html -e xml -e txt -e asc)
+brotli_files := $(patsubst %, %.br, $(to_compress))
+gzip_files := $(patsubst %, %.gz, $(to_compress))
+zstd_files := $(patsubst %, %.zst, $(to_compress))
+
+%.html.br: %.html
+	@echo $@
+	$(brotli) $<
+
+%.xml.br: %.xml
+	@echo $@
+	$(brotli) $<
+
+%.txt.br: %.txt
+	@echo $@
+	$(brotli) $<
+
+%.asc.br: %.asc
+	@echo $@
+	$(brotli) $<
+
+%.html.gz: %.html
+	@echo $@
+	$(gzip) $<
+
+%.xml.gz: %.xml
+	$(gzip) $<
+
+%.txt.gz: %.txt
+	@echo $@
+	$(gzip) $<
+
+%.asc.gz: %.asc
+	@echo $@
+	$(gzip) $<
+
+%.html.zst: %.html
+	@echo $@
+	$(zstd) $< > $@
+
+%.xml.zst: %.xml
+	@echo $@
+	$(zstd) $< > $@
+
+%.txt.zst: %.txt
+	@echo $@
+	$(zstd) $< > $@
+
+%.asc.zst: %.asc
+	@echo $@
+	$(zstd) $< > $@
+
+compress: .compressstamp
+
+.compressstamp: .formatstamp $(brotli_files) $(gzip_files) $(zstd_files)
+	@echo "Compressing output files..."
+	@touch .compressstamp
+
+deploy: .deploystamp
+
+.deploystamp: .compressstamp Caddyfile redis.Caddyfile Dockerfile fly.toml
+	fly deploy
+	@touch .deploystamp
+
+.PHONY: all clean build format compress deploy