🐛 Replace file if content is different
This commit is contained in:
parent
ddb3af1f46
commit
7459f2b158
|
@ -48,9 +48,42 @@ find -L "$SOURCE_DIR" -type f -name "*.md" -exec grep -q "publish: true" {} \; -
|
||||||
|
|
||||||
# Check if the destination file already exists
|
# Check if the destination file already exists
|
||||||
if [ -f "$dest_path" ]; then
|
if [ -f "$dest_path" ]; then
|
||||||
echo "Skipped $markdown_file as it already exists in $dest_path" >> "$LOG_FILE"
|
# Compare the source and destination files
|
||||||
|
if cmp -s "$markdown_file" "$dest_path"; then
|
||||||
|
echo "Skipped $markdown_file as it already exists and has the same content in $dest_path" >> "$LOG_FILE"
|
||||||
else
|
else
|
||||||
# Copy the Markdown file
|
# Replace the destination file with the source file
|
||||||
|
cp -p "$markdown_file" "$dest_path"
|
||||||
|
echo "Replaced $dest_path with $markdown_file" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
# Extract and copy referenced images
|
||||||
|
grep -o '\!\[\[.*\]\]' "$markdown_file" | sed 's/\!\[\[\(.*\)\]\]/\1/' | while IFS= read -r image_ref; do
|
||||||
|
# Check if image_ref is a relative path
|
||||||
|
if [[ ! "$image_ref" =~ ^/ ]]; then
|
||||||
|
image_ref="$SOURCE_DIR/$image_ref"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Try to find the image recursively within SOURCE_DIR
|
||||||
|
image_path=$(find -L "$SOURCE_DIR" -type f -name "$(basename "$image_ref")" -print -quit)
|
||||||
|
|
||||||
|
# Debugging: Print image_path
|
||||||
|
echo "Checking image_path: $image_path" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
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/"
|
||||||
|
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
|
||||||
|
echo "Image reference $image_ref in $markdown_file does not exist." >> "$LOG_FILE"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Copy the Markdown file since it doesn't exist in the destination
|
||||||
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"
|
||||||
|
|
||||||
|
@ -82,6 +115,7 @@ find -L "$SOURCE_DIR" -type f -name "*.md" -exec grep -q "publish: true" {} \; -
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
# Find Markdown files with "publish: false" and process them
|
# Find Markdown files with "publish: false" and process them
|
||||||
find -L "$SOURCE_DIR" -type f -name "*.md" -exec grep -q "publish: false" {} \; -exec grep -l "publish: false" {} + | while read -r markdown_file; do
|
find -L "$SOURCE_DIR" -type f -name "*.md" -exec grep -q "publish: false" {} \; -exec grep -l "publish: false" {} + | while read -r markdown_file; do
|
||||||
# Extract relative path from the source directory
|
# Extract relative path from the source directory
|
||||||
|
|
Loading…
Reference in New Issue