#!/bin/sh
set -eu
mkdir -p static/preview static/thumbnail
resize() {
local photo=$1 size=$2 output=$3
if ! test -f $output; then
# FIXME: convert complains about not understanding XML
echo $output >&2
convert $photo -auto-orient -thumbnail $size $output 2>/dev/null ||:
fi
}
preview() {
local photo=$1
local preview=preview/${photo##*/}
resize $photo 1500000@ static/$preview
echo $preview
}
thumbnail() {
local photo=$1
local thumbnail=thumbnail/${photo##*/}
resize $photo 60000@ static/$thumbnail
echo $thumbnail
}
encode() {
sed '
s/&/\&/g
s/\</g
s/"/\"/g
' "$@"
}
page_title() {
date -j -f '%F' $1 '+%B %e, %Y'
}
page_head() {
local date=$1
local title=$(page_title $date)
local body lens film
if test -f $date/body; then
body=$(encode $date/body)
fi
if test -f $date/lens; then
lens=$(encode $date/lens)
else
lens=$(
identify -format '%[EXIF:LensModel]' \
$date/$(ls -1 $date | head -n 1) 2>/dev/null |
sed '
s/\([A-Z]\)\([0-9]\)/\1 \2/
s,f/,ƒ/,
s/\([0-9]\)-\([0-9]\)/\1–\2/g
' |
encode
)
fi
if test -f $date/film; then
film=$(encode $date/film)
fi
cat <<-EOF