feat: ADD header and footer modifier for title etc
This commit is contained in:
parent
be696c343c
commit
30e6956fa4
4 changed files with 47 additions and 4 deletions
43
build.sh
43
build.sh
|
|
@ -14,12 +14,22 @@ ASSETS_DIR="assets"
|
||||||
# Opt out with STRIP_EXIF=0 or --keep-exif.
|
# Opt out with STRIP_EXIF=0 or --keep-exif.
|
||||||
STRIP_EXIF="${STRIP_EXIF:-1}"
|
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
|
for arg in "$@"; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
--keep-exif) STRIP_EXIF=0 ;;
|
--keep-exif) STRIP_EXIF=0 ;;
|
||||||
|
--no-footer) SHOW_FOOTER=0 ;;
|
||||||
|
--title=*) GALLERY_TITLE="${arg#--title=}" ;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
echo "usage: ./build.sh [--keep-exif]"
|
echo "usage: ./build.sh [--keep-exif] [--no-footer] [--title=TEXT]"
|
||||||
echo " --keep-exif do not strip image metadata (env: STRIP_EXIF=0)"
|
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 ;;
|
exit 0 ;;
|
||||||
*) echo "unknown option: $arg" >&2; exit 1 ;;
|
*) echo "unknown option: $arg" >&2; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -33,6 +43,18 @@ if [[ "$STRIP_EXIF" == "1" ]] && ! command -v exiftool >/dev/null 2>&1; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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
|
# Create output directory
|
||||||
mkdir -p "$OUTPUT_DIR"
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
|
@ -42,8 +64,27 @@ OUTPUT_FILE="$OUTPUT_DIR/index.html"
|
||||||
|
|
||||||
# Assemble templates in order
|
# Assemble templates in order
|
||||||
for template in $(ls "$TEMPLATES_DIR"/*.tmpl | sort); do
|
for template in $(ls "$TEMPLATES_DIR"/*.tmpl | sort); do
|
||||||
|
skip_block=0
|
||||||
# Process each template line by line to handle placeholders
|
# Process each template line by line to handle placeholders
|
||||||
while IFS= read -r line; do
|
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
|
if [[ "$line" == *"<!-- IMAGES -->"* ]]; then
|
||||||
# Generate gallery items (reversed order)
|
# Generate gallery items (reversed order)
|
||||||
images=("$IMAGES_DIR"/*)
|
images=("$IMAGES_DIR"/*)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta name="description" content="Image gallery powered by shellery">
|
<meta name="description" content="Image gallery powered by shellery">
|
||||||
<meta name="generator" content="shellery">
|
<meta name="generator" content="shellery">
|
||||||
<title>Gallery</title>
|
<title><!-- TITLE --></title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
<link rel="icon" href="favicon.ico">
|
<link rel="icon" href="favicon.ico">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
<header>
|
<header>
|
||||||
<h1>Gallery</h1>
|
<h1><!-- TITLE --></h1>
|
||||||
</header>
|
</header>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
<!-- LIGHTBOXES -->
|
<!-- LIGHTBOXES -->
|
||||||
|
<!-- IF_FOOTER -->
|
||||||
<footer>
|
<footer>
|
||||||
<p>Powered by <a href="https://git.uphillsecurity.com/cf7/shellery" target="_blank" rel="noopener">shellery</a></p>
|
<p>Powered by <a href="https://git.uphillsecurity.com/cf7/shellery" target="_blank" rel="noopener">shellery</a></p>
|
||||||
</footer>
|
</footer>
|
||||||
|
<!-- ENDIF_FOOTER -->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue