⚡ Remove excessive logging and skip copy if file already exists
This commit is contained in:
parent
5357fbb572
commit
dcdcb0e8a8
|
@ -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,30 +33,40 @@ 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"
|
||||||
|
|
||||||
# Copy the Markdown file
|
# Check if the destination file already exists
|
||||||
cp -p "$markdown_file" "$dest_path"
|
if [ -f "$dest_path" ]; then
|
||||||
echo "Copied $markdown_file to $dest_path" >> "$LOG_FILE"
|
echo "Skipped $markdown_file as it already exists in $dest_path" >> "$LOG_FILE"
|
||||||
|
else
|
||||||
|
# Copy the Markdown file
|
||||||
|
cp -p "$markdown_file" "$dest_path"
|
||||||
|
echo "Copied $markdown_file to $dest_path" >> "$LOG_FILE"
|
||||||
|
|
||||||
# Extract and copy referenced images
|
# Extract and copy referenced images
|
||||||
grep -o '\!\[\[.*\]\]' "$markdown_file" | sed 's/\!\[\[\(.*\)\]\]/\1/' | while IFS= read -r image_ref; do
|
grep -o '\!\[\[.*\]\]' "$markdown_file" | sed 's/\!\[\[\(.*\)\]\]/\1/' | while IFS= read -r image_ref; do
|
||||||
# Check if image_ref is a relative path
|
# Check if image_ref is a relative path
|
||||||
if [[ ! "$image_ref" =~ ^/ ]]; then
|
if [[ ! "$image_ref" =~ ^/ ]]; then
|
||||||
image_ref="$SOURCE_DIR/$image_ref"
|
image_ref="$SOURCE_DIR/$image_ref"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Try to find the image recursively within SOURCE_DIR
|
# Try to find the image recursively within SOURCE_DIR
|
||||||
image_path=$(find -L "$SOURCE_DIR" -type f -name "$(basename "$image_ref")" -print -quit)
|
image_path=$(find -L "$SOURCE_DIR" -type f -name "$(basename "$image_ref")" -print -quit)
|
||||||
|
|
||||||
# Debugging: Print image_path
|
# Debugging: Print image_path
|
||||||
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
|
||||||
cp "$image_path" "$IMAGE_DIR/"
|
# Check if the image already exists in IMAGE_DIR
|
||||||
echo "Copied image $image_ref to $IMAGE_DIR/" >> "$LOG_FILE"
|
if [ ! -f "$IMAGE_DIR/$(basename "$image_ref")" ]; then
|
||||||
else
|
cp "$image_path" "$IMAGE_DIR/"
|
||||||
echo "Image reference $image_ref in $markdown_file does not exist." >> "$LOG_FILE"
|
echo "Copied image $image_ref to $IMAGE_DIR/" >> "$LOG_FILE"
|
||||||
fi
|
else
|
||||||
done
|
echo "Skipped copying image $image_ref as it already exists in $IMAGE_DIR/" >> "$LOG_FILE"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Image reference $image_ref in $markdown_file does not exist." >> "$LOG_FILE"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Print the log file
|
# Print the log file
|
||||||
|
|
Loading…
Reference in New Issue