hugo: Watch for changes with hugo watch

In addition to changes made when Git repositories update, Hugo is able
to watch for timed changes to content (say, for content that has a
publication date in the future) and build these automatically.

This commit switches from a plain `hugo build` to a `hugo watch` process
to facilitate these use-cases.
This commit is contained in:
Alex Palaistras 2022-07-11 21:18:23 +01:00
parent c1e326d211
commit da043fce5e

View File

@ -19,10 +19,14 @@ elif test ! -e "/src/${GIT_REPO}/refs/heads/${GIT_BRANCH}"; then
fi
chown -R hugo:hugo /dest
gosu hugo git clone --quiet --shared --branch "${GIT_BRANCH}" "/src/${GIT_REPO}" /tmp/src
# Wait for updates to watched branch for the given site, and build static content anew.
while true; do
gosu hugo git clone --quiet --shared --branch "${GIT_BRANCH}" "/src/${GIT_REPO}" /tmp/src
gosu hugo hugo --verbose --source /tmp/src --destination /dest && rm -Rf /tmp/src
inotifywait -qq --event modify "/src/${GIT_REPO}/refs/heads/${GIT_BRANCH}" && break
done
(
cd /tmp/src
while inotifywait -qq --event modify "/src/${GIT_REPO}/refs/heads/${GIT_BRANCH}"; do
gosu hugo git fetch origin "${GIT_BRANCH}" && gosu hugo git reset --hard "${GIT_BRANCH}"
done
) &
gosu hugo hugo watch --verbose --source /tmp/src --destination /dest