Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

jasonnerothin commented Jan 3, 2018

Thanks for the gist.

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