From da043fce5e4496e587a794fb4fcc31f1d52c1d99 Mon Sep 17 00:00:00 2001 From: Alex Palaistras Date: Mon, 11 Jul 2022 21:18:23 +0100 Subject: [PATCH] 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. --- service/hugo/container/run-hugo | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/service/hugo/container/run-hugo b/service/hugo/container/run-hugo index 3f83b50..84fe0f9 100755 --- a/service/hugo/container/run-hugo +++ b/service/hugo/container/run-hugo @@ -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