squeeze

A static site generator that can put the toothpaste back in the tube.
git clone https://git.mulligrubs.me/squeeze
Log | Files | Refs | README | LICENSE

commit 9ae36242606ecb980677782f087df053f3daee2e
parent fc16a3eec14ad64d5ba477e03472369a5b235676
Author: St John Karp <stjohn@fuzzjunket.com>
Date:   Tue, 31 Mar 2020 12:41:24 -0500

Delete files for which the source was removed

Because we're no longer flushing and recreating everything, we need
to check to see if there are any output files that no longer exist
in the source. rsync takes care of this for assets, but we need
a manual implementation for Markdown/HTML. This works both ways,
both for squeezing and unsqueezing.

Diffstat:
Msqueeze.sh | 15++++++++++++++-
Munsqueeze.sh | 11+++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/squeeze.sh b/squeeze.sh @@ -9,11 +9,24 @@ SITE_PATH=$1 # This will also create the folder structure for the destination Markdown files. rsync --archive --delete --verbose --exclude "*.md" --exclude "*.html" --exclude "feeds" "$SITE_PATH/$SOURCE_DIR/" "$SITE_PATH/$OUTPUT_DIR/" +# Delete any HTML files for which the source was removed. +find "$SITE_PATH/$OUTPUT_DIR" -type f -name "*.html" -print0 | + while IFS= read -r -d '' file; do + OLD_PATH=`echo "$file" | + sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" | + sed 's|.html$|.md|'` + if [ ! -f $OLD_PATH ]; then + rm $file + fi + done + # Parse and create all the HTML files. find "$SITE_PATH/$SOURCE_DIR" -type f -name "*.md" -print0 | while IFS= read -r -d '' file; do echo $file - NEW_PATH=`echo "$file" | sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" | sed 's|.md$|.html|'` + NEW_PATH=`echo "$file" | + sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" | + sed 's|.md$|.html|'` # Only process files whose destination doesn't exist, or which has been recently changed. if [ ! -f $NEW_PATH ] || [[ $(find $file -mtime -7) ]]; then # Get everything after the metadata and feed it through Pandoc. diff --git a/unsqueeze.sh b/unsqueeze.sh @@ -10,6 +10,17 @@ SITE_PATH=$1 # This will also create the folder structure for the destination Markdown files. rsync --archive --delete --verbose --exclude "*.html" --exclude "*.md" --exclude "feeds" "$SITE_PATH/$OUTPUT_DIR/" "$SITE_PATH/$SOURCE_DIR/" +# Delete any Markdown files for which the output was removed. +find "$SITE_PATH/$SOURCE_DIR" -type f -name "*.md" -print0 | + while IFS= read -r -d '' file; do + OLD_PATH=`echo "$file" | + sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" | + sed 's|.md$|.html|'` + if [ ! -f $OLD_PATH ]; then + rm $file + fi + done + # Parse and create all the markdown files. find "$SITE_PATH/$OUTPUT_DIR" -type f -name "*.html" -print0 | while IFS= read -r -d '' file; do