Add clean function

This commit is contained in:
Gal 2024-02-15 00:15:16 +01:00
parent c91fe60268
commit 5ffd94d9ca
Signed by: gal
GPG Key ID: F035BC65003BC00B
3 changed files with 24 additions and 23 deletions

View File

@ -8,12 +8,13 @@ help:
@echo " publish Restart Docker Compose (or run 'npx quartz build --serve' with local=True)."
@echo " preview Run 'npx quartz build --serve' with specific directories."
compress-images:
@./scripts/compress_images.sh
# Target-specific variables for the publish target
publish:
@./scripts/publish.sh "$(SOURCE_DIR)" "$(DEST_DIR)"
@if [ "$(clean)" = "True" ]; then \
./scripts/publish.sh "$(SOURCE_DIR)" "$(DEST_DIR)" True; \
else \
./scripts/publish.sh "$(SOURCE_DIR)" "$(DEST_DIR)"; \
fi
@if [ "$(local)" = "True" ]; then \
echo "Running npx quartz build --serve"; \
npx quartz build --serve; \

View File

@ -21,15 +21,15 @@ make publish
```
## How this works
- From local obsidian, sync to remote obsidian
- In local I read from local vault and copy to content all that have tag publish=True
- In remote I read from remove vault and copy to content all that have tag publish=True
- In remote I read from remote vault and copy to content all that have tag publish=True
## Improvements
- scripts/publish.sh:
- [ ] Skip copying files that already exist
- [ ] Resize image to 60% for faster load
- [x] Skip copying files that already exist
- [x] Resize image to 60% for faster load
- [x] Keep source and destination dirs in sync
- [x] add restart/publish to make
---

View File

@ -1,18 +1,31 @@
#!/bin/bash
# Check if both SOURCE_DIR and DEST_DIR are provided as arguments
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <SOURCE_DIR> <DEST_DIR>"
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <SOURCE_DIR> <DEST_DIR> [clean=True/False]"
exit 1
fi
# Capture SOURCE_DIR and DEST_DIR from arguments
SOURCE_DIR="$1"
DEST_DIR="$2"
CLEAN_FLAG="${3:-False}" # Default value is False if not provided
IMAGE_DIR="$DEST_DIR/images"
# Ensure destination directories exist
mkdir -p "$DEST_DIR"
# Function to clean DEST_DIR
clean_destination() {
echo "Cleaning $DEST_DIR"
rm -rf "$DEST_DIR"/*
}
# Check if CLEAN_FLAG is set to True
if [ "$CLEAN_FLAG" == "True" ]; then
clean_destination
fi
mkdir -p "$IMAGE_DIR"
# Temporary log for copied files
@ -69,19 +82,6 @@ find -L "$SOURCE_DIR" -type f -name "*.md" -exec grep -q "publish: true" {} \; -
fi
done
# Delete files in DEST_DIR that don't exist in SOURCE_DIR anymore
find "$DEST_DIR" -type f -exec sh -c '
relative_path=${1#$DEST_DIR/}
source_file="$SOURCE_DIR/$relative_path"
if [ ! -e "$source_file" ]; then
echo "Delete $1"
rm "$1"
else
echo "Skipping $1 as it exists in SOURCE_DIR"
fi
' _ {} \;
# Print the log file
cat "$LOG_FILE"