From edebcf570a8218bd828e607d7cba882db45ffaac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Sun, 28 Jan 2024 18:15:49 +0200 Subject: [PATCH] combine blog and djangostatic --- app/e11sync/settings.py | 3 --- app/e11sync/static/style.css | 1 + blog/assets/static | 1 + blog/config.yaml | 4 --- .../default/layouts/_default/baseof.html | 2 +- flake.nix | 1 + overlay.nix | 1 + pkgs/e11sync-blog.nix | 19 ++++++++++++++ pkgs/e11sync-static.nix | 26 ++++++++++++++++--- 9 files changed, 47 insertions(+), 11 deletions(-) create mode 120000 app/e11sync/static/style.css create mode 120000 blog/assets/static create mode 100644 pkgs/e11sync-blog.nix diff --git a/app/e11sync/settings.py b/app/e11sync/settings.py index 45a3229..8d0a3ea 100644 --- a/app/e11sync/settings.py +++ b/app/e11sync/settings.py @@ -110,11 +110,8 @@ USE_TZ = True STATIC_URL = 'static/' -STATICFILES_DIRS = [BASE_DIR / ".." / "static"] - STATICFILES_FINDERS = [ "django.contrib.staticfiles.finders.AppDirectoriesFinder", - "django.contrib.staticfiles.finders.FileSystemFinder", ] STORAGES = { diff --git a/app/e11sync/static/style.css b/app/e11sync/static/style.css new file mode 120000 index 0000000..b296d1a --- /dev/null +++ b/app/e11sync/static/style.css @@ -0,0 +1 @@ +../../../static/style.css \ No newline at end of file diff --git a/blog/assets/static b/blog/assets/static new file mode 120000 index 0000000..8e9b74c --- /dev/null +++ b/blog/assets/static @@ -0,0 +1 @@ +../../static \ No newline at end of file diff --git a/blog/config.yaml b/blog/config.yaml index 8576b94..fa4ce10 100644 --- a/blog/config.yaml +++ b/blog/config.yaml @@ -25,7 +25,3 @@ outputFormats: RSS: mediatype: "application/rss" baseName: "rss" -module: - mounts: - - source: ../static - target: assets diff --git a/blog/themes/default/layouts/_default/baseof.html b/blog/themes/default/layouts/_default/baseof.html index 7a4c2a3..4141243 100644 --- a/blog/themes/default/layouts/_default/baseof.html +++ b/blog/themes/default/layouts/_default/baseof.html @@ -4,7 +4,7 @@ {{ partial "html-meta.html" . -}} {{ if not (or .IsHome .IsSection) }}{{ .Title }} - {{ end }}{{ .Site.Title }} -{{ $css := resources.Get "style.scss" | resources.ToCSS (dict "transpiler" "dartsass" "enableSourceMap" false) | resources.Fingerprint }} +{{ $css := resources.Get "static/style.scss" | resources.ToCSS (dict "transpiler" "dartsass" "enableSourceMap" false) | resources.Fingerprint }} {{ with .Site.Params.favicon -}} diff --git a/flake.nix b/flake.nix index 255dd37..6f5d73c 100644 --- a/flake.nix +++ b/flake.nix @@ -46,6 +46,7 @@ packages = { inherit (pkgs) + e11sync-blog e11sync-static e11sync-djangostatic e11sync-caddyfile diff --git a/overlay.nix b/overlay.nix index 9dd05f7..7250e9a 100644 --- a/overlay.nix +++ b/overlay.nix @@ -12,6 +12,7 @@ in { geoip-mmdb = withDjango5.callPackage ./pkgs/geoip-mmdb.nix { inherit geoip2-tarball; }; + e11sync-blog = withDjango5.callPackage ./pkgs/e11sync-blog.nix {}; e11sync-static = withDjango5.callPackage ./pkgs/e11sync-static.nix {}; e11sync-djangostatic = withDjango5.callPackage ./pkgs/e11sync-djangostatic.nix {}; e11sync-caddyfile = withDjango5.callPackage ./pkgs/e11sync-caddyfile.nix {}; diff --git a/pkgs/e11sync-blog.nix b/pkgs/e11sync-blog.nix new file mode 100644 index 0000000..7902652 --- /dev/null +++ b/pkgs/e11sync-blog.nix @@ -0,0 +1,19 @@ +{ + stdenv, + dart-sass, + hugo, +}: +stdenv.mkDerivation rec { + name = "e11sync-blog"; + srcs = [../blog ../static]; + nativeBuildInputs = [dart-sass]; + sourceRoot = "."; + buildPhase = '' + cd blog + ${hugo}/bin/hugo --printPathWarnings --panicOnWarning + ''; + installPhase = '' + mkdir -p $out + mv public/{static,blog,contact} $out/ + ''; +} diff --git a/pkgs/e11sync-static.nix b/pkgs/e11sync-static.nix index 7e0979a..749c9d0 100644 --- a/pkgs/e11sync-static.nix +++ b/pkgs/e11sync-static.nix @@ -3,19 +3,39 @@ zopfli, brotli, findutils, + e11sync-blog, e11sync-djangostatic, }: runCommand "e11sync-static" { - src = e11sync-djangostatic; + srcs = [e11sync-djangostatic e11sync-blog]; nativeBuildInputs = [findutils]; + sourceRoot = "."; } '' unpackPhase - find e11sync-djangostatic \ + + # 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 + fi + + mkdir -p $out + mv e11sync-djangostatic/* $out/ + mv --no-clobber e11sync-blog/{static,blog,contact} $out/ + + find $out \ -name '*.css' -or \ -name '*.js' -or \ -name '*.svg' -or \ + -name '*.html' -or \ -name '*.txt' | \ tee >(xargs -n1 -P''$(nproc) ${zopfli}/bin/zopfli) | \ xargs -n1 -P''$(nproc) ${brotli}/bin/brotli - mv e11sync-djangostatic $out ''