feat: ADD header and footer modifier for title etc

This commit is contained in:
Caffeine Fueled 2026-08-21 06:56:23 +02:00
parent be696c343c
commit 30e6956fa4
Signed by: cf7
GPG key ID: CA295D643074C68C
4 changed files with 47 additions and 4 deletions

View file

@ -14,12 +14,22 @@ ASSETS_DIR="assets"
# Opt out with STRIP_EXIF=0 or --keep-exif.
STRIP_EXIF="${STRIP_EXIF:-1}"
# Page title, used for both <title> and the <h1> header
GALLERY_TITLE="${GALLERY_TITLE:-Gallery}"
# Show the "Powered by shellery" footer; set to 0 to hide it
SHOW_FOOTER="${SHOW_FOOTER:-1}"
for arg in "$@"; do
case "$arg" in
--keep-exif) STRIP_EXIF=0 ;;
--no-footer) SHOW_FOOTER=0 ;;
--title=*) GALLERY_TITLE="${arg#--title=}" ;;
-h|--help)
echo "usage: ./build.sh [--keep-exif]"
echo " --keep-exif do not strip image metadata (env: STRIP_EXIF=0)"
echo "usage: ./build.sh [--keep-exif] [--no-footer] [--title=TEXT]"
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)"
exit 0 ;;
*) echo "unknown option: $arg" >&2; exit 1 ;;
esac
@ -33,6 +43,18 @@ if [[ "$STRIP_EXIF" == "1" ]] && ! command -v exiftool >/dev/null 2>&1; then
exit 1
fi
# Escape text destined for HTML body content
html_escape() {
local s=$1
# Replacements are quoted: bash 5.2+ expands an unquoted & to the matched text
s="${s//&/"&amp;"}"
s="${s//</"&lt;"}"
s="${s//>/"&gt;"}"
printf '%s' "$s"
}
TITLE_HTML=$(html_escape "$GALLERY_TITLE")
# Create output directory
mkdir -p "$OUTPUT_DIR"
@ -42,8 +64,27 @@ OUTPUT_FILE="$OUTPUT_DIR/index.html"
# Assemble templates in order
for template in $(ls "$TEMPLATES_DIR"/*.tmpl | sort); do
skip_block=0
# Process each template line by line to handle placeholders
while IFS= read -r line; do
# Optional block: <!-- IF_FOOTER --> ... <!-- ENDIF_FOOTER -->
if [[ "$line" == *"<!-- IF_FOOTER -->"* ]]; then
if [[ "$SHOW_FOOTER" != "1" ]]; then
skip_block=1
fi
continue
fi
if [[ "$line" == *"<!-- ENDIF_FOOTER -->"* ]]; then
skip_block=0
continue
fi
if [[ "$skip_block" == "1" ]]; then
continue
fi
# Replacement is quoted: bash 5.2+ expands an unquoted & to the matched text
line="${line//<!-- TITLE -->/"$TITLE_HTML"}"
if [[ "$line" == *"<!-- IMAGES -->"* ]]; then
# Generate gallery items (reversed order)
images=("$IMAGES_DIR"/*)