#!/bin/bash WATCH_DIR="content/posts" PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)" LIBS_DIR="static/libs" LIBS_URL="/libs" echo "🚨 Watching ${WATCH_DIR} for changes..." inotifywait -m -e close_write --format '%w%f' -r "$WATCH_DIR" | while read FILE; do if [[ "$FILE" == *.Rmd ]]; then POST_DIR=$(dirname "$FILE") echo "🔄 Change detected in $FILE. Rendering..." (cd "$POST_DIR" && Rscript -e 'renv::load("'"${PROJECT_ROOT}"'"); statdown::statdown_render("index.Rmd", output_root = "'"${PROJECT_ROOT}/${LIBS_DIR}"'", url_root = "'"${LIBS_URL}"'")') echo "✅ Rendered ${FILE}" fi done