From 1e4195ea9d936987352468aebd57b6b9af98c93c Mon Sep 17 00:00:00 2001 From: Felix Albrigtsen Date: Sun, 14 Apr 2024 02:04:18 +0200 Subject: [PATCH] bekkalokk: pvv-nettsiden-gallery: Improve thumbnail generation --- hosts/bekkalokk/services/website/fetch-gallery.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hosts/bekkalokk/services/website/fetch-gallery.nix b/hosts/bekkalokk/services/website/fetch-gallery.nix index 59b17ed..9b72977 100644 --- a/hosts/bekkalokk/services/website/fetch-gallery.nix +++ b/hosts/bekkalokk/services/website/fetch-gallery.nix @@ -34,8 +34,8 @@ in { # Delete files and directories that exists in the gallery that don't exist in the tarball filesToRemove=$(uniq -u <(sort <(find . -not -path "./.thumbnails*") <(tar -tf ${transferDir}/gallery.tar.gz | sed 's|/$||'))) while IFS= read fname; do - rm -f $fname ||: - rm -f .thumbnails/$fname.png ||: + rm -f "$fname" ||: + rm -f ".thumbnails/$fname.png" ||: done <<< "$filesToRemove" find . -type d -empty -delete @@ -44,11 +44,17 @@ in { images=$(find . -type f -not -path "./.thumbnails*") while IFS= read fname; do - [ -f ".thumbnails/$fname.png" ] && continue ||: + # Skip this file if an up-to-date thumbnail already exists + if [ -f ".thumbnails/$fname.png" ] && \ + [ "$(date -R -r "$fname")" == "$(date -R -r ".thumbnails/$fname.png")" ] + then + continue + fi echo "Creating thumbnail for $fname" mkdir -p $(dirname ".thumbnails/$fname") - convert -define jpeg:size=200x200 "$fname" -thumbnail 500 -auto-orient ".thumbnails/$fname.png" ||: + convert -define jpeg:size=200x200 "$fname" -thumbnail 300 -auto-orient ".thumbnails/$fname.png" ||: + touch -m -d "$(date -R -r "$fname")" ".thumbnails/$fname.png" done <<< "$images" '';