gal 1.56 KB
Newer Older
Lysander Trischler's avatar
Add gal  
Lysander Trischler committed
1 2
#!/bin/sh

3 4
while true; do
    case "$1" in
5
        -h|--help) echo "$0 [-h|--help] [-u|--nav-url URL] [-t|--nav-title TITLE] [-p|--profile PROFILE] [--] TITLE"; exit 0;;
6 7
        -u|--nav-url) nav_url="$2"; shift 2;;
        -t|--nav-title) nav_title="$2"; shift 2;;
8 9 10 11 12 13 14 15 16 17 18 19
        -p|--profile)
            profile_file="$(readlink -f "$0").$2.sh"; shift 2
            if [ ! -e "$profile_file" ]; then
                echo "$0: Profile file $profile_file not found" >&2
                exit 3
            fi
            if [ ! -r "$profile_file" ]; then
                echo "$0: Profile file $profile_file is not readable" >&2
                exit 4
            fi
            # shellcheck source=gal.natur.sh
            . "$profile_file";;
20 21 22 23 24 25 26 27 28
        --) shift; break;;
        -*) echo "$0: Unknown option '$1', use '--' to separate page title from options" >&2; exit 1;;
        *) break;;
    esac
done
if [ -n "$nav_title" ] && [ -z "$nav_url" ]; then
    echo "$0: The -t/--nav-title option was specified, but -u/--nav-url is missing" >&2
    exit 2
fi
Lysander Trischler's avatar
Lysander Trischler committed
29
title="${*:-$(basename "$PWD")}"
Lysander Trischler's avatar
Add gal  
Lysander Trischler committed
30 31 32 33 34 35 36 37 38 39 40 41 42

cat > index.html <<EOF
<!DOCTYPE html>
<meta charset=utf-8 />
<title>$title</title>
<style>*{font-family:sans-serif}</style>
<h1>$title</h1>
EOF

for img in ??.jpg; do
    echo "<a href=$img style=cursor:zoom-in><img src=$(basename "$img" .jpg)-vorschau.jpg alt=\"$title\" /></a>" >> index.html
done

43 44 45
if [ -n "$nav_url" ]; then
    echo "<hr /><nav><a href=$nav_url>${nav_title:-$nav_url}</a></nav>" >> index.html
fi
46 47 48 49 50

# gal_hook would be defined in the profile
if type gal_hook > /dev/null; then
    gal_hook
fi