Add clean function
This commit is contained in:
parent
c91fe60268
commit
5ffd94d9ca
9
Makefile
9
Makefile
|
@ -8,12 +8,13 @@ help:
|
||||||
@echo " publish Restart Docker Compose (or run 'npx quartz build --serve' with local=True)."
|
@echo " publish Restart Docker Compose (or run 'npx quartz build --serve' with local=True)."
|
||||||
@echo " preview Run 'npx quartz build --serve' with specific directories."
|
@echo " preview Run 'npx quartz build --serve' with specific directories."
|
||||||
|
|
||||||
compress-images:
|
|
||||||
@./scripts/compress_images.sh
|
|
||||||
|
|
||||||
# Target-specific variables for the publish target
|
# Target-specific variables for the publish target
|
||||||
publish:
|
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 \
|
@if [ "$(local)" = "True" ]; then \
|
||||||
echo "Running npx quartz build --serve"; \
|
echo "Running npx quartz build --serve"; \
|
||||||
npx quartz build --serve; \
|
npx quartz build --serve; \
|
||||||
|
|
|
@ -21,15 +21,15 @@ make publish
|
||||||
```
|
```
|
||||||
|
|
||||||
## How this works
|
## How this works
|
||||||
|
|
||||||
- From local obsidian, sync to remote obsidian
|
- 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 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
|
## Improvements
|
||||||
- scripts/publish.sh:
|
- scripts/publish.sh:
|
||||||
- [ ] Skip copying files that already exist
|
- [x] Skip copying files that already exist
|
||||||
- [ ] Resize image to 60% for faster load
|
- [x] Resize image to 60% for faster load
|
||||||
|
- [x] Keep source and destination dirs in sync
|
||||||
- [x] add restart/publish to make
|
- [x] add restart/publish to make
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,31 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Check if both SOURCE_DIR and DEST_DIR are provided as arguments
|
# Check if both SOURCE_DIR and DEST_DIR are provided as arguments
|
||||||
if [ "$#" -ne 2 ]; then
|
if [ "$#" -lt 2 ]; then
|
||||||
echo "Usage: $0 <SOURCE_DIR> <DEST_DIR>"
|
echo "Usage: $0 <SOURCE_DIR> <DEST_DIR> [clean=True/False]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 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"
|
||||||
|
CLEAN_FLAG="${3:-False}" # Default value is False if not provided
|
||||||
IMAGE_DIR="$DEST_DIR/images"
|
IMAGE_DIR="$DEST_DIR/images"
|
||||||
|
|
||||||
# Ensure destination directories exist
|
# Ensure destination directories exist
|
||||||
mkdir -p "$DEST_DIR"
|
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"
|
mkdir -p "$IMAGE_DIR"
|
||||||
|
|
||||||
# Temporary log for copied files
|
# Temporary log for copied files
|
||||||
|
@ -69,19 +82,6 @@ find -L "$SOURCE_DIR" -type f -name "*.md" -exec grep -q "publish: true" {} \; -
|
||||||
fi
|
fi
|
||||||
done
|
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
|
# Print the log file
|
||||||
cat "$LOG_FILE"
|
cat "$LOG_FILE"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue