commit b97c754c0de48b3fa4910b7946fac6fd1545a89e
parent 257d62e923fc8764459912496e3187f201fe90d4
Author: St John Karp <contact@stjo.hn>
Date: Mon, 30 Mar 2020 16:01:40 -0500
Use rsync and conditionals to improve speed
Use rsync instead of deleting/copying everything every time.
This ensures we'll only copy assets that have changed.
Implemented some conditionals for the Markdown processing so that
we only output HTML files which don't already exist or for which
the source file has changed in the last seven days.
These changes should make a big improvement in the speed on
subsequent runs.
Diffstat:
2 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/squeeze.sh b/squeeze.sh
@@ -6,7 +6,6 @@ SOURCE_DIR=source
SITE_PATH=$1
# Create the directory structure.
-rm -rf "$SITE_PATH"/"$OUTPUT_DIR"/*
find "$SITE_PATH"/"$SOURCE_DIR" -type d |
sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|" |
xargs -0 -d '\n' mkdir -p --
@@ -16,21 +15,20 @@ 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|'`
- # Get everything after the metadata and feed it through Pandoc.
- sed "1,/^$/d" "$file" |
- pandoc --ascii --from markdown+smart --to html |
- # Recombine with the metadata and hand it to Prolog.
- (sed "/^$/q" "$file" && cat) |
- swipl --traditional -q -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), generate_entry." \
- > "$NEW_PATH"
+ # 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.
+ sed "1,/^$/d" "$file" |
+ pandoc --ascii --from markdown+smart --to html |
+ # Recombine with the metadata and hand it to Prolog.
+ (sed "/^$/q" "$file" && cat) |
+ swipl --traditional -q -l parse_entry.pl -g "consult('$SITE_PATH/site.pl'), generate_entry." \
+ > "$NEW_PATH"
+ fi
done
# Copy anything else directly.
-find "$SITE_PATH"/"$SOURCE_DIR" -type f -not -name "*.md" -print0 |
- while IFS= read -r -d '' file; do
- NEW_PATH=`echo "$file" | sed "s|^$SITE_PATH/$SOURCE_DIR|$SITE_PATH/$OUTPUT_DIR|"`
- cp "$file" "$NEW_PATH"
- done
+rsync --archive --delete --verbose --exclude "*.md" --exclude "*.html" --exclude "feeds" "$SITE_PATH/$SOURCE_DIR/" "$SITE_PATH/$OUTPUT_DIR/"
# Generate the RSS feed.
mkdir -p "$SITE_PATH"/"$OUTPUT_DIR"/feeds
diff --git a/unsqueeze.sh b/unsqueeze.sh
@@ -6,7 +6,6 @@ SOURCE_DIR=source
SITE_PATH=$1
# Create the directory structure.
-rm -rf "$SITE_PATH"/"$SOURCE_DIR"/*
find "$SITE_PATH"/"$OUTPUT_DIR" -type d |
sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|" |
xargs -0 -d '\n' mkdir -p --
@@ -28,8 +27,4 @@ find "$SITE_PATH"/"$OUTPUT_DIR" -type f -name "*.html" -print0 |
# Copy anything else directly.
# Excludes the RSS folder, which we create ourselves upon generation.
-find "$SITE_PATH"/"$OUTPUT_DIR" -path "$SITE_PATH"/"$OUTPUT_DIR"/feeds -prune -o -type f -not -name "*.html" -print0 |
- while IFS= read -r -d '' file; do
- NEW_PATH=`echo "$file" | sed "s|^$SITE_PATH/$OUTPUT_DIR|$SITE_PATH/$SOURCE_DIR|"`
- cp "$file" "$NEW_PATH"
- done
-\ No newline at end of file
+rsync --archive --delete --verbose --exclude "*.html" --exclude "*.md" --exclude "feeds" "$SITE_PATH/$OUTPUT_DIR/" "$SITE_PATH/$SOURCE_DIR/"
+\ No newline at end of file