Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Lego2012
Last active January 3, 2018 12:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lego2012/5e0d5b7619bb6205f24d5244c405010a to your computer and use it in GitHub Desktop.
Save Lego2012/5e0d5b7619bb6205f24d5244c405010a to your computer and use it in GitHub Desktop.
Leo's Hugo build scripts #hugo

The BaseURL in config.yml is set to /.

The domains.sh holds the URLs for Production Build and Stage Build.

do-dev.sh takes just the BaseURL from config.yml. When it comes to Stage or Build Production the BaseURLs are taken from do-prod.sh or do-stage.sh. And those are feeded by domains.sh.

Although this is a convenient way to create different builds be aware of the risk of the source command in the do- files. If you like to know more about it: Google is your friend.

#!/bin/zsh
# These are the BaseURLs for do-stage.sh and do-prod.sh
export BASE_STAGE="http://test.domain.tld/"
export BASE_PROD="http://domain.tld/"
# These are the directories on the server where the builds are published to
export DIR_STAGE="/test.domain.tld/"
export DIR_PROD="/domain.tld/"
#!/bin/zsh
DIR=$(pwd -P)
BUILD_DIR="/build/dev"
if [ -d $DIR$BUILD_DIR ]
then
rm -rf $DIR$BUILD_DIR
echo Directory $DIR$BUILD_DIR deleted
else
echo Directory $DIR$BUILD_DIR not existing
fi
HUGO_ENV="development" hugo server --buildDrafts --buildFuture --destination $DIR$BUILD_DIR
#!/bin/zsh
source domains.sh
DIR=$(pwd -P)
BUILD_DIR="/build/public"
if [ -d $DIR$BUILD_DIR ]
then
rm -rf $DIR$BUILD_DIR
echo Directory $DIR$BUILD_DIR deleted
else
echo Directory $DIR$BUILD_DIR not existing
fi
# The variable $BASE_PROD comes from domains.sh
# You can start Hugo with server or not like here
HUGO_ENV="production" Hugo --baseURL $BASE_PROD --destination $DIR$BUILD_DIR
#!/bin/zsh
source domains.sh
DIR=$(pwd -P)
BUILD_DIR="/build/stage"
if [ -d $DIR$BUILD_DIR ]
then
rm -rf $DIR$BUILD_DIR
echo Directory $DIR$BUILD_DIR deleted
else
echo Directory $DIR$BUILD_DIR not existing
fi
# The variable $BASE_STAGE comes from domains.sh
# You can start Hugo with server or not like here
HUGO_ENV="stage" Hugo --baseURL $BASE_STAGE --destination $DIR$BUILD_DIR
@jasonnerothin
Copy link

Thanks for the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment