#!/bin/bash
 
# --- Configuration ---
# Path to your local Quartz repository
QUARTZ_REPO_PATH="/home/kiet/Obsidian/quartz/"
 
# Path to your Obsidian Vault
OBSIDIAN_VAULT_PATH="/home/kiet/Obsidian/"
OBSIDIAN_SHARING_PATH="/home/kiet/Obsidian/Sharing/"
 
# Server details for transferring files
REMOTE_USER="root"
REMOTE_HOST="lukaxzs.myaddr.io"
REMOTE_WWW_PATH="/var/www/quartz"
 
# --- Script ---
echo "Copying desired directories..."
rsync -a --delete-after "$OBSIDIAN_VAULT_PATH/Learning/Formal/Year 5 - Semester 1/PBL6" "$OBSIDIAN_SHARING_PATH"
rsync -a --delete-after "$OBSIDIAN_VAULT_PATH/Learning/Formal/Year 5 - Semester 1/Intelligent Robotics" "$OBSIDIAN_SHARING_PATH"
 
echo "Building Quartz site..."
 
# Navigate to the Quartz repository and build the site
cd "$QUARTZ_REPO_PATH" || exit
npx quartz build --directory "$OBSIDIAN_SHARING_PATH"
 
echo "Build complete. Transferring files to server..."
 
# Transfer the contents of the 'public' folder to your server
# The --delete flag removes any old files on the server that are no longer in the new build
rsync -avz --delete "$QUARTZ_REPO_PATH/public/" "${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_WWW_PATH}/"
 
echo "Update successful!"