Remove excessive logging and skip copy if file already exists

This commit is contained in:
Gal 2024-02-13 22:31:09 +01:00
parent 5357fbb572
commit dcdcb0e8a8
Signed by: gal
GPG Key ID: F035BC65003BC00B
1 changed files with 33 additions and 26 deletions

View File

@ -6,9 +6,6 @@ if [ "$#" -ne 2 ]; then
exit 1 exit 1
fi fi
# Debugging: Print commands as they are executed
set -x
# Capture SOURCE_DIR and DEST_DIR from arguments # Capture SOURCE_DIR and DEST_DIR from arguments
SOURCE_DIR="$1" SOURCE_DIR="$1"
DEST_DIR="$2" DEST_DIR="$2"
@ -36,6 +33,10 @@ find -L "$SOURCE_DIR" -type f -name "*.md" -exec grep -q "publish: true" {} \; -
dest_dir=$(dirname "$dest_path") dest_dir=$(dirname "$dest_path")
mkdir -p "$dest_dir" mkdir -p "$dest_dir"
# Check if the destination file already exists
if [ -f "$dest_path" ]; then
echo "Skipped $markdown_file as it already exists in $dest_path" >> "$LOG_FILE"
else
# Copy the Markdown file # Copy the Markdown file
cp -p "$markdown_file" "$dest_path" cp -p "$markdown_file" "$dest_path"
echo "Copied $markdown_file to $dest_path" >> "$LOG_FILE" echo "Copied $markdown_file to $dest_path" >> "$LOG_FILE"
@ -54,12 +55,18 @@ find -L "$SOURCE_DIR" -type f -name "*.md" -exec grep -q "publish: true" {} \; -
echo "Checking image_path: $image_path" >> "$LOG_FILE" echo "Checking image_path: $image_path" >> "$LOG_FILE"
if [ -f "$image_path" ]; then if [ -f "$image_path" ]; then
# Check if the image already exists in IMAGE_DIR
if [ ! -f "$IMAGE_DIR/$(basename "$image_ref")" ]; then
cp "$image_path" "$IMAGE_DIR/" cp "$image_path" "$IMAGE_DIR/"
echo "Copied image $image_ref to $IMAGE_DIR/" >> "$LOG_FILE" echo "Copied image $image_ref to $IMAGE_DIR/" >> "$LOG_FILE"
else
echo "Skipped copying image $image_ref as it already exists in $IMAGE_DIR/" >> "$LOG_FILE"
fi
else else
echo "Image reference $image_ref in $markdown_file does not exist." >> "$LOG_FILE" echo "Image reference $image_ref in $markdown_file does not exist." >> "$LOG_FILE"
fi fi
done done
fi
done done
# Print the log file # Print the log file