From 47d1ba611b6b3a675dc55fb210395d45938d67dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sun, 28 Jan 2024 22:47:10 +0200 Subject: [PATCH] caddy: handle /contact and /blog --- flake.nix | 2 +- pkgs/e11sync-caddyfile.nix | 9 +++++++-- pkgs/e11sync-static.nix | 24 +++++++++++------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/flake.nix b/flake.nix index 6914883..099d588 100644 --- a/flake.nix +++ b/flake.nix @@ -75,7 +75,7 @@ }; apps = { - e11sync-caddyfile = { + e11sync-caddy = { type = "app"; name = "e11sync-caddyfile"; program = toString (pkgs.writeShellScript "wrapper" '' diff --git a/pkgs/e11sync-caddyfile.nix b/pkgs/e11sync-caddyfile.nix index ad8d7c1..769caaf 100644 --- a/pkgs/e11sync-caddyfile.nix +++ b/pkgs/e11sync-caddyfile.nix @@ -6,10 +6,15 @@ writeTextFile { name = "e11sync-caddyfile"; text = '' + @addSlash path /static /blog /contact + route @addSlash { + redir {uri}/ 302 + } + header /static/* Cache-Control "public, max-age=31536000, immutable" - route /static/* { - uri strip_prefix /static + @staticRoutes path /static/* /contact/* /blog/* + route @staticRoutes { file_server * { root ${e11sync-static} precompressed br gzip diff --git a/pkgs/e11sync-static.nix b/pkgs/e11sync-static.nix index 749c9d0..92171cc 100644 --- a/pkgs/e11sync-static.nix +++ b/pkgs/e11sync-static.nix @@ -13,22 +13,20 @@ runCommand "e11sync-static" { } '' unpackPhase - # check that {e11sync-djangostatic,e11sync-blog/static/style.*.css - # is the same file - hash1=$(echo e11sync-djangostatic/static/style.*.css | sed 's;.*/;;' ) - hash2=$(echo e11sync-blog/static/style.*.css | sed 's;.*/;;' ) - - if [ "$hash1" != "$hash2" ]; then - { - echo "style.*.css in blog and django do not match:" - ls e11sync-djangostatic/style/style.*.css - ls blog/style/style.*.css - } >&2 + if ! cmp \ + e11sync-djangostatic/style.*.css \ + e11sync-blog/static/style.*.css + then + echo "style.*.css in blog and djangostatic do not match:" + ls -l e11sync-djangostatic/style/style.*.css blog/style/style.*.css + exit 1 fi + rm e11sync-djangostatic/style.*.css + mkdir -p $out - mv e11sync-djangostatic/* $out/ - mv --no-clobber e11sync-blog/{static,blog,contact} $out/ + mv e11sync-blog/{static,blog,contact} $out/ + mv --no-clobber e11sync-djangostatic/* $out/static/ find $out \ -name '*.css' -or \