diff --git a/Makefile b/Makefile index 97b7f80..3fd8027 100644 --- a/Makefile +++ b/Makefile @@ -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; \ diff --git a/README.md b/README.md index 63d4721..475bbff 100644 --- a/README.md +++ b/README.md @@ -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 --- diff --git a/scripts/publish.sh b/scripts/publish.sh index 5166b9e..5df80f5 100755 --- a/scripts/publish.sh +++ b/scripts/publish.sh @@ -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 " +if [ "$#" -lt 2 ]; then + echo "Usage: $0 [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"