Extract shared config into .env, source from all scripts

SITE_DIR, HUGO_IMAGE, PORT defined once in .env.
Scripts source it instead of duplicating definitions.
This commit is contained in:
Jean-Michel Tremblay 2026-04-03 17:17:19 -04:00
parent 688fd8f16c
commit 9a9de04e04
4 changed files with 13 additions and 14 deletions

8
.env Normal file
View file

@ -0,0 +1,8 @@
# Shared configuration for all scripts.
# Sourced by scripts/*.sh — do not use Docker --env-file with this.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[1]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
SITE_DIR="${PROJECT_ROOT}/site"
HUGO_IMAGE="ghcr.io/gohugoio/hugo:latest"
PORT="${PORT:-1313}"

View file

@ -4,11 +4,8 @@ set -euo pipefail
# Build and serve the Hugo site locally using Docker.
# Usage: ./scripts/build.sh
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
SITE_DIR="${PROJECT_ROOT}/site"
HUGO_IMAGE="ghcr.io/gohugoio/hugo:latest"
PORT="${1:-1313}"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../.env"
PORT="${1:-$PORT}"
if [[ ! -d "${SITE_DIR}" ]]; then
echo "[build] Site directory not found: ${SITE_DIR}"

View file

@ -4,11 +4,8 @@ set -euo pipefail
# Serve the Hugo site locally using Docker.
# Usage: ./scripts/serve.sh
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
SITE_DIR="${PROJECT_ROOT}/site"
HUGO_IMAGE="ghcr.io/gohugoio/hugo:latest"
PORT="${1:-1313}"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../.env"
PORT="${1:-$PORT}"
if [[ ! -d "${SITE_DIR}" ]]; then
echo "[serve] Site directory not found: ${SITE_DIR}"

View file

@ -4,10 +4,7 @@ set -euo pipefail
# Initialize a Hugo site with the Terminal theme using Docker.
# Usage: ./scripts/setup.sh
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
SITE_DIR="${PROJECT_ROOT}/site"
HUGO_IMAGE="ghcr.io/gohugoio/hugo:latest"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../.env"
hugo() {
docker run --rm \