web/_scripts/sh/sync_monitor.sh

39 lines
688 B
Bash
Raw Normal View History

2019-11-05 17:18:31 +08:00
#!/bin/bash
2020-06-01 00:45:48 -06:00
# Files sync monitor
2020-01-02 21:17:49 +08:00
# v2.0
# https://github.com/cotes2020/jekyll-theme-chirpy
2019-11-05 17:18:31 +08:00
# © 2019 Cotes Chung
# MIT Licensed
2019-11-18 21:37:09 +08:00
# $1 -> the origin file with absolute path.
2019-11-05 17:18:31 +08:00
# $2 -> the origin sync directory
2020-06-01 00:45:48 -06:00
# $3 -> the destination sync directory
2019-11-05 17:18:31 +08:00
2019-11-18 21:37:09 +08:00
# Omit the system temp file
2020-08-19 17:05:58 +08:00
if [[ ! -f "$1" ]]; then
2019-11-05 17:18:31 +08:00
exit 0
fi
2020-08-19 17:05:58 +08:00
src_dir="$(dirname $(realpath "$1"))"
2019-11-05 17:18:31 +08:00
2020-08-19 17:05:58 +08:00
dir_prefix="$(realpath "$2")/"
2019-11-05 17:18:31 +08:00
related_dir="${src_dir:${#dir_prefix}}"
2020-08-19 17:05:58 +08:00
dest="$(realpath "$3")/${related_dir}"
2019-11-05 17:18:31 +08:00
if [[ ! -d "$dest" ]]; then
mkdir -p "$dest"
fi
if [[ -f "$1" ]]; then
2020-08-19 17:05:58 +08:00
cp "$1" "$dest"
2019-11-05 17:18:31 +08:00
fi
2020-08-19 17:05:58 +08:00
if [[ "$related_dir" == "_posts" ]]; then
bash "$3"/_scripts/sh/create_pages.sh
bash "$3"/_scripts/sh/dump_lastmod.sh
2019-11-05 17:18:31 +08:00
fi