about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAlan Pearce2023-05-14 23:00:46 +0200
committerAlan Pearce2023-05-14 23:00:46 +0200
commit8aefb7152057742ed815e3bce9ce5a6299b03683 (patch)
tree76ba7f064dc93b975b5e5401ddc7c9951f11a27d
parentf9fffe7e4084066fd7077ff951976e4108defdf8 (diff)
downloadwebsite-8aefb7152057742ed815e3bce9ce5a6299b03683.tar.lz
website-8aefb7152057742ed815e3bce9ce5a6299b03683.tar.zst
website-8aefb7152057742ed815e3bce9ce5a6299b03683.zip
Pre-compress built site with brotli/zstd/gzip
-rw-r--r--Makefile55
-rw-r--r--flake.nix3
2 files changed, 58 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..17c7548
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,55 @@
+.SHELLFLAGS := -eu -o pipefail -c
+.ONESHELL:
+.DELETE_ON_ERROR:
+
+brotli := brotli --force
+gzip := gzip --best --keep --force
+zstd := zstd --force --no-pass-through -19 --quiet
+
+build:
+	zola build
+
+to_compress := $(shell fd . public --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))
+
+public/%.html.br: public/%.html
+	$(brotli) $<
+
+public/%.xml.br: public/%.xml
+	$(brotli) $<
+
+public/%.txt.br: public/%.txt
+	$(brotli) $<
+
+public/%.asc.br: public/%.asc
+	$(brotli) $<
+
+public/%.html.gz: public/%.html
+	$(gzip) $<
+
+public/%.xml.gz: public/%.xml
+	$(gzip) $<
+
+public/%.txt.gz: public/%.txt
+	$(gzip) $<
+
+public/%.asc.gz: public/%.asc
+	$(gzip) $<
+
+public/%.html.zst: public/%.html
+	$(zstd) $<
+
+public/%.xml.zst: public/%.xml
+	$(zstd) $<
+
+public/%.txt.zst: public/%.txt
+	$(zstd) $<
+
+public/%.asc.zst: public/%.asc
+	$(zstd) $<
+
+compress: $(brotli_files) $(gzip_files) $(zstd_files)
+
+.PHONY: all build compress
diff --git a/flake.nix b/flake.nix
index 8f31cfd..7403f7e 100644
--- a/flake.nix
+++ b/flake.nix
@@ -11,6 +11,9 @@
       {
         devShells.default = pkgs.mkShell {
           packages = with pkgs; [
+            brotli
+            gzip
+            zstd
             gnugrep
             git
             zola