From 79b82efe8902cb1269372008afd5792afab37df7 Mon Sep 17 00:00:00 2001 From: Volpeon Date: Tue, 22 Dec 2020 11:32:19 +0100 Subject: Fine-grained compilation when watching --- scripts/build_content.sh | 33 +++++++++++++++++++++++++++++---- scripts/watch_content.sh | 10 +++++++--- scripts/watch_sass.sh | 4 ++-- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/scripts/build_content.sh b/scripts/build_content.sh index 4476d45..992414d 100755 --- a/scripts/build_content.sh +++ b/scripts/build_content.sh @@ -2,7 +2,32 @@ SITE_TITLE="Volpeon's Den" -find content/ \ - -iname "*.md" \ - -type f \ - -exec sh -c 'TARGET=dist/$(echo ${0%.md}.html | cut -sd / -f 2-); mkdir -p $(dirname $TARGET) && pandoc "${0}" -t html5 --template templates/base.html -o "$TARGET" --metadata sitetitle="$1"' {} "$SITE_TITLE" \; +target () { + echo "dist/$(echo ${1%.md}.html | cut -sd / -f 2-)" +} + +compile () { + TARGET=$(target "$1") + mkdir -p $(dirname "$TARGET") + pandoc "$1" \ + -t html5 \ + --template templates/base.html \ + -o "$TARGET" \ + --metadata sitetitle="$SITE_TITLE" +} + +if [ -z "$1" ]; then + find content/ \ + -iname "*.md" \ + -type f \ + | while read FILE + do + compile "$FILE" + done +else + if [ "$2" = "delete" ]; then + rm $(target $1) + else + compile "$1" + fi +fi diff --git a/scripts/watch_content.sh b/scripts/watch_content.sh index d2578e1..38567dc 100755 --- a/scripts/watch_content.sh +++ b/scripts/watch_content.sh @@ -1,8 +1,12 @@ #!/bin/bash -inotifywait -m -e create -e close_write --format "%f" content \ +inotifywait -rme create,close_write,delete,move --format "%f" content \ | while read FILENAME do - printf "Change detected: %s\n" "$FILENAME" - scripts/build_content.sh + printf "Change detected: %s\n" "content/$FILENAME" + if [ -f "content/$FILENAME" ]; then + scripts/build_content.sh "content/$FILENAME" + else + scripts/build_content.sh "content/$FILENAME" "delete" + fi done diff --git a/scripts/watch_sass.sh b/scripts/watch_sass.sh index e7b2952..1b99f5d 100755 --- a/scripts/watch_sass.sh +++ b/scripts/watch_sass.sh @@ -1,8 +1,8 @@ #!/bin/bash -inotifywait -m -e create -e close_write --format "%f" assets \ +inotifywait -rme create,close_write,delete,move --format "%f" assets \ | while read FILENAME do - printf "Change detected: %s\n" "$FILENAME" + printf "Change detected: %s\n" "assets/$FILENAME" scripts/build_sass.sh done -- cgit v1.2.3-70-g09d2