From d0373f0198d2d68e9b3a88d5723c891e4e572443 Mon Sep 17 00:00:00 2001 From: CaffeineFueled Date: Fri, 21 Aug 2026 07:01:29 +0200 Subject: [PATCH] feat: ADD work with local .env file #14 --- .env.example | 24 ++++++++++++++++++++++++ .gitignore | 3 +++ README.md | 37 +++++++++++++++++++++++++++++++++++++ build.sh | 17 +++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..e8e00a6 --- /dev/null +++ b/.env.example @@ -0,0 +1,24 @@ +# Shellery configuration +# +# cp .env.example .env +# +# Every value below is the built-in default, so an unedited copy changes +# nothing. .env is read from the working directory and is gitignored. +# +# Precedence: command line flags > environment > .env > these defaults. +# This file is sourced by build.sh, so shell syntax applies. + +# Page title. Used for both and the <h1> header. +# Special characters are HTML-escaped automatically. +# Flag: --title=TEXT +GALLERY_TITLE="Gallery" + +# Show the "Powered by shellery" footer. 1 = show, 0 = hide. +# Flag: --no-footer +SHOW_FOOTER=1 + +# Strip EXIF/GPS/IPTC/XMP metadata from the images copied into output/. +# 1 = strip (requires exiftool), 0 = publish metadata as-is. +# Source images in images/ are never modified either way. +# Flag: --keep-exif +STRIP_EXIF=1 diff --git a/.gitignore b/.gitignore index 021d4a3..01ebe7f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ output/* # Ignore content in images directory images/* !images/.gitkeep + +# Local configuration (see .env.example) +.env diff --git a/README.md b/README.md index f908ab5..ad01fcf 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Simple SSG to create dynamic gallery one-pagers in your shell! Shell+Gallery **Available**: - Simple use, single dependency (exiftool) - Removes EXIF/GPS metadata from published images by default +- Configurable title and optional footer via environment variables - no Javascript - Lightbox of image with anchor - Order of images via filename @@ -70,6 +71,42 @@ docker run -v $(pwd)/images:/app/images -v $(pwd)/output:/app/output localhost/s The generated gallery will be in `./output/index.html` +### Configuration + +All options can be set in a `.env` file, as environment variables, or as flags. +`.env.example` lists every option with its default, so an unedited copy changes nothing: + +```bash +cp .env.example .env +``` + +`.env` is gitignored. Precedence is **flags > environment > `.env` > defaults**, so a +`-e` value passed to the container still wins over the file. Point `ENV_FILE` at another +path to use a different file. + +| Variable | Flag | Default | Effect | +|---|---|---|---| +| `GALLERY_TITLE` | `--title=TEXT` | `Gallery` | Page `<title>` and the `<h1>` header | +| `SHOW_FOOTER` | `--no-footer` | `1` | Set to `0` to hide the "Powered by shellery" footer | +| `STRIP_EXIF` | `--keep-exif` | `1` | Set to `0` to publish image metadata as-is | +| `ENV_FILE` | - | `.env` | Path to the config file to load | + +```bash +GALLERY_TITLE="Holiday 2026" SHOW_FOOTER=0 ./build.sh +# or +./build.sh --title="Holiday 2026" --no-footer + +# container, via -e +podman run -e GALLERY_TITLE="Holiday 2026" -e SHOW_FOOTER=0 \ + -v $(pwd)/images:/app/images -v $(pwd)/output:/app/output \ + git.uphillsecurity.com/cf7/shellery:latest + +# container, via a mounted .env +podman run -v $(pwd)/.env:/app/.env:ro \ + -v $(pwd)/images:/app/images -v $(pwd)/output:/app/output \ + git.uphillsecurity.com/cf7/shellery:latest +``` + ### Metadata removal EXIF, GPS, IPTC and XMP metadata is stripped from every image by default. Only the copies diff --git a/build.sh b/build.sh index 2b22d7c..0c3303b 100755 --- a/build.sh +++ b/build.sh @@ -10,6 +10,20 @@ OUTPUT_DIR="output" TEMPLATES_DIR="templates" ASSETS_DIR="assets" +# Load .env if present; see .env.example for every option and its default. +# Precedence: command line flags > environment > .env > built-in defaults. +ENV_FILE="${ENV_FILE:-.env}" +if [[ -f "$ENV_FILE" ]]; then + # Remember caller-supplied values so the file cannot clobber them + env_override=$(export -p | grep -E '^declare -x (STRIP_EXIF|GALLERY_TITLE|SHOW_FOOTER)=' || true) + # shellcheck source=/dev/null + source "$ENV_FILE" + if [[ -n "$env_override" ]]; then + eval "$env_override" + fi + unset env_override +fi + # Image metadata (EXIF/GPS/IPTC/XMP) is stripped by default. # Opt out with STRIP_EXIF=0 or --keep-exif. STRIP_EXIF="${STRIP_EXIF:-1}" @@ -30,6 +44,9 @@ for arg in "$@"; do echo " --keep-exif do not strip image metadata (env: STRIP_EXIF=0)" echo " --no-footer hide the 'Powered by shellery' footer (env: SHOW_FOOTER=0)" echo " --title=TEXT page title and header, default 'Gallery' (env: GALLERY_TITLE)" + echo "" + echo "Options may also be set in .env (see .env.example)." + echo "Precedence: flags > environment > .env > defaults." exit 0 ;; *) echo "unknown option: $arg" >&2; exit 1 ;; esac