From 2f2484df935bc8d1a731adf4b30774cd6e4d67fb Mon Sep 17 00:00:00 2001 From: Hyperling Date: Mon, 2 Nov 2026 15:08:59 -0700 Subject: [PATCH] hugo, allow specifying the baseURL since it's helpful for SEO and other things, also rename PORT variables to not collide with Ansible's PROD_PORT. --- Config/HugoExample/Dockerfile | 2 +- Config/HugoExample/docker-compose.example.yml | 9 +++++---- Config/HugoExample/example.env | 10 ++++++---- Config/HugoExample/files/cronjob.sh | 3 ++- Config/HugoExample/files/main.sh | 11 +++++++++-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Config/HugoExample/Dockerfile b/Config/HugoExample/Dockerfile index edd4f22..2dc5781 100644 --- a/Config/HugoExample/Dockerfile +++ b/Config/HugoExample/Dockerfile @@ -47,4 +47,4 @@ RUN chmod +x /root/main.sh ## Main ## # Install + Run Website WORKDIR /var/www/ -CMD /root/main.sh "$REPO" "$BRANCH" "$PROD" "$DEV" +CMD /root/main.sh "$REPO" "$BRANCH" "$PROD" "$DEV" "$BASEURL" diff --git a/Config/HugoExample/docker-compose.example.yml b/Config/HugoExample/docker-compose.example.yml index 61374dc..c27f1c6 100644 --- a/Config/HugoExample/docker-compose.example.yml +++ b/Config/HugoExample/docker-compose.example.yml @@ -9,13 +9,14 @@ services: image: hyperling/hugo:$BRANCH restart: always ports: - - $PROD_PORT:80 # Production minified files served using NGINX. - #- $DEV_PORT:1380 # Development files with drafts served by Hugo Server. + - $NGINX_PORT:80 # Production minified files served using NGINX. + #- $HUGO_PORT:1380 # Development files with drafts served by Hugo Server. environment: - REPO=$REPO - BRANCH=$BRANCH - - PROD=$PROD - - DEV=$DEV + - PROD=$NGINX + - DEV=$HUGO + - BASEURL=$BASEURL healthcheck: test: curl -sS http://localhost:80 || curl -sS http://localhost:1380 || exit 1 interval: 1m diff --git a/Config/HugoExample/example.env b/Config/HugoExample/example.env index 785a0db..7c22400 100644 --- a/Config/HugoExample/example.env +++ b/Config/HugoExample/example.env @@ -16,12 +16,14 @@ BRANCH=prod # Please use values YES/TRUE and NO/FALSE. # Whether to start NGINX -PROD=YES -PROD_PORT=8013 +NGINX=YES +NGINX_PORT=8013 # Whether to start Hugo Server -DEV=NO -DEV_PORT=1380 +HUGO=NO +HUGO_PORT=1380 + +BASEURL=https://blog.hyperling.com # ## Resources ## diff --git a/Config/HugoExample/files/cronjob.sh b/Config/HugoExample/files/cronjob.sh index 4f541b5..aad61a9 100644 --- a/Config/HugoExample/files/cronjob.sh +++ b/Config/HugoExample/files/cronjob.sh @@ -3,6 +3,7 @@ cd /var/www/hugo/site FORCE="$1" +BASEURL="$2" echo "*** Running cronjob @ `date` ***" @@ -16,7 +17,7 @@ if [[ $status != 0 && -e /var/www/html/index.html && -z $FORCE ]]; then fi # If the project was not already up to date, build the new files for NGINX. -/usr/local/bin/hugo --gc --minify +/usr/local/bin/hugo $BASEURL --gc --minify status="$?" echo "* Hugo status is '$status', FORCE is '$FORCE'." if [[ $status == 0 && -e public/index.html ]]; then diff --git a/Config/HugoExample/files/main.sh b/Config/HugoExample/files/main.sh index ea32e57..7ac34d3 100644 --- a/Config/HugoExample/files/main.sh +++ b/Config/HugoExample/files/main.sh @@ -17,6 +17,13 @@ DEV="$4" typeset -u DEV echo "DEV='$DEV'" +BASEURL="$5" +echo "BASEURL='$BASEURL'" +baseurl="" +if [[ -n "$BASEURL" ]]; then + baseurl="-b $BASEURL" +fi + SITE="/var/www/hugo/site" CLONE="/var/www/hugo/site-new" @@ -40,7 +47,7 @@ mv -v $CLONE $SITE echo "*** Copying Static Files to NGINX ***" rm -rfv /var/www/html/* -sudo -u www-data /var/www/hugo/cronjob.sh +sudo -u www-data /var/www/hugo/cronjob.sh "" "$baseurl" echo "*** Starting Cron ***" service cron start @@ -73,7 +80,7 @@ if [[ "$DEV" == "Y"* || "$DEV" == "T"* ]]; then echo "* Dev server not detected, starting..." cd $SITE killall hugo 2>/dev/null - sudo -u www-data hugo server -D -F --noBuildLock --bind 0.0.0.0 -p 1380 & + sudo -u www-data hugo server $baseurl -D -F --noBuildLock --bind 0.0.0.0 -p 1380 & fi sleep 30 done &