Skip to content

Commit

Permalink
_scripts: do not render serve to disk
Browse files Browse the repository at this point in the history
This ensures we don't have any removed artefacts lying around when hugo
serves its content. This can happen if we remove a page, which then (via
runPreprocessor.bash) gets removed from hugo/content, but the contents
of _public can still linger around between serve invocations, because
hugo does not remove them by default.

Also remove _public along with hugo/content when running the
preprocessor in execute (non-serve) mode, to ensure we really don't
leave any artefacts lying around when we publish the site.

Signed-off-by: Paul Jolly <[email protected]>
Change-Id: I6a1a5896fc8cdf5bc7c3c031cafdc0bf9533812f
Dispatch-Trailer: {"type":"trybot","CL":1169678,"patchset":1,"ref":"refs/changes/78/1169678/1","targetBranch":"alpha"}
  • Loading branch information
myitcv authored and cueckoo committed Sep 19, 2023
1 parent 962841f commit 6f6ba4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
13 changes: 7 additions & 6 deletions _scripts/runPreprocessor.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ fi

GOBIN=$PWD/.gobin go install -trimpath -buildvcs=false ./internal/cmd/preprocessor

# Remove preprocessor target directory. This ensures we don't leave any stale
# files lying around. Slight hack: only do so if we are running the execute command.
# Note this ties this script to _scripts/serve.bash so if making changes to order
# or args in that script, make changes to the check here.
# Remove preprocessor and hugo target directories. This ensures we don't leave
# any stale files lying around. Slight hack: only do so if we are running the
# execute command (but not when running with the --serve flag) . Note this ties
# this script to _scripts/serve.bash so if making changes to order or args in
# that script, make changes to the check here.
#
# TODO: make the prepreprocess smart enough to do this itself.
# TODO: make the prepreprocessor smart enough to do this itself.
if [[ "${1:-}" == "execute" && "${2:-}" != "--serve" ]]; then
rm -rf hugo/content
rm -rf _public hugo/content
fi

exec $PWD/.gobin/preprocessor "$@"
7 changes: 5 additions & 2 deletions _scripts/serve.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ set -eux
# cd to the parent directory to that containing the script
cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.."

# Run the preprocess in serve mode which will itself run hugo
source _scripts/runPreprocessor.bash execute --serve --hugo '-D' --hugo '--renderToDisk' --debug=hugo "$@"
# Run the preprocess in serve mode which will itself run hugo.
# Do not render to disk, to avoid any removed files lingering
# in local serve mode (hugo does not tidy these with default
# behaviour).
source _scripts/runPreprocessor.bash execute --serve --hugo '-D' --debug=hugo "$@"

0 comments on commit 6f6ba4b

Please sign in to comment.