Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 43 additions & 23 deletions scripts/localbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e

# USAGE:
# 1. Install Hugo: https://www.docsy.dev/docs/getting-started/#install-hugo
#
#
# 2. For Mac OSX: The script uses the `gnu` version of `sed`. To install `gnu-sed`, you use brew:
# 1. Run `brew install gnu-sed`
# 2. Add it to your `PATH`. For example, add the following line to your `~/.bash_profile`:
Expand Down Expand Up @@ -52,6 +52,11 @@ BUILDALLRELEASES="false"
BUILDSINGLEBRANCH="false"
PRBUILD="false"

# Default Hugo build options
# disable Hugo server
SERVER=""
# disable live reload
LIVERELOAD=" --watch=false --disableLiveReload"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primary change (1/3) - by default disable Hugo server live reload


# OPTIONS:
#
Expand All @@ -68,28 +73,39 @@ PRBUILD="false"
#
# USAGE: Append the -a true to the command.
# Example:
# ./scripts/build.sh -a true -s
#
# ./scripts/build.sh -a true -s true
#
# Examples:
# - Default local clone static HTML build:
#
# - Default: Build local clone to static HTML (output to 'public' folder):
# ./scripts/localbuild.sh
#
# - Local clone build with localhost server:
# ./scripts/localbuild.sh -s
# - Locally build knative.dev:
# ./scripts/localbuild.sh -a true
#
# - Clone all docs releases from knative/docs and then run local build:
# ./scripts/localbuild.sh -a true -s
# - Run Hugo server (localhost):
#
# - Locally build content from specified fork and branch:
# ./scripts/localbuild.sh -f repofork -b branchname -s
# - Local clone build (-s true):
# ./scripts/localbuild.sh -s true
#
# - Locally build a specific version from $FORK:
# ./scripts/localbuild.sh -b branchname -s
# - Local clone build with live reload (-s reload):
# - Useful for website changes only (doesn't work on docs)
# ./scripts/localbuild.sh -s reload
#
SERVER=""
while getopts f:b:a:s arg; do
case $arg in
# - Additional build options - build from remote Fork and Branch:
#
# - Build content from specified fork and branch:
# - Build any branch from your fork or from someones in a PR
# ./scripts/localbuild.sh -f REPOFORK -b BRANCHNAME
#
# - Locally build a specific branch from $FORK ($DEFAULTFORK):
# ./scripts/localbuild.sh -b BRANCHNAME
#
# - Combine other -s or -a flags. Example:
# ./scripts/localbuild.sh -f my-docs-contributor-fork -a true -s reload
#
while getopts "f:b:a:s:" arg; do
case "${arg}" in
f)
echo '--- BUILDING FROM ---'
echo 'FORK:' "${OPTARG}"
Expand All @@ -109,20 +125,24 @@ while getopts f:b:a:s arg; do
;;
a)
echo 'BUILDING ALL RELEASES FROM KNATIVE/DOCS'
# If 'true', all knative/docs branches are built to mimic a
# "production" build.
# REQUIRED: If you specify a fork ($FORK), all of the same branches
# If 'true', all knative/docs branches are built to mimic a
# "production" build.
# REQUIRED: If you specify a fork ($FORK), all of the same branches
# (with the same branch names) that are built in knative.dev must
# also exist and be available in the that $FORK (ie, 'release-0.X').
# See /config/production/params.toml for the list of the branches
# their names that are currently built in knative.dev.
# also exist and be available in the that $FORK (ie, 'release-0.X').
# See scripts/docs-version-settings.sh for the list of the built branches.
BUILDALLRELEASES="${OPTARG}"
BUILDENVIRONMENT="production"
BUILDSINGLEBRANCH="false"
;;
s)
echo 'Running hugo in server mode'
echo 'Running Hugo server'
SERVER="server"
if [ "${OPTARG}" = "reload" ]; then
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primary change (2/3) - if you use the "reload" flag, enable live reload in Hugo server

echo 'with live reload'
LIVERELOAD=" --disableFastRender --renderToDisk"
fi
;;
esac
done

Expand All @@ -134,7 +154,7 @@ source scripts/processsourcefiles.sh

# BUILD MARKDOWN
# Start HUGO build
hugo $SERVER --baseURL "" --environment "$BUILDENVIRONMENT"
hugo $SERVER --baseURL "" --environment "$BUILDENVIRONMENT" $LIVERELOAD --gc
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

primary change (3/3) - also added --gc to clean cache each time (ie. using live reload is useful only for site updates) https://gohugo.io/commands/hugo_server/


if [ -z "$SERVER" ]; then
echo ''
Expand Down