From 30e6956fa4a7cc493df84add614ea023ffb0496e Mon Sep 17 00:00:00 2001 From: CaffeineFueled Date: Fri, 21 Aug 2026 06:56:23 +0200 Subject: [PATCH] feat: ADD header and footer modifier for title etc --- build.sh | 45 ++++++++++++++++++++++++++++++++++++++-- templates/00_meta.tmpl | 2 +- templates/10_header.tmpl | 2 +- templates/90_footer.tmpl | 2 ++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index 4222e0e..2b22d7c 100755 --- a/build.sh +++ b/build.sh @@ -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 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//&/"&"}" + s="${s//</"<"}" + s="${s//>/">"}" + 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"/*) diff --git a/templates/00_meta.tmpl b/templates/00_meta.tmpl index 6503001..7a025fe 100644 --- a/templates/00_meta.tmpl +++ b/templates/00_meta.tmpl @@ -5,7 +5,7 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="Image gallery powered by shellery"> <meta name="generator" content="shellery"> - <title>Gallery + <!-- TITLE --> diff --git a/templates/10_header.tmpl b/templates/10_header.tmpl index 4f67869..3283e41 100644 --- a/templates/10_header.tmpl +++ b/templates/10_header.tmpl @@ -1,3 +1,3 @@
-

Gallery

+

diff --git a/templates/90_footer.tmpl b/templates/90_footer.tmpl index a744170..2ceba0d 100644 --- a/templates/90_footer.tmpl +++ b/templates/90_footer.tmpl @@ -1,6 +1,8 @@ + +