#!/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//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 ${title}

${title}

📷 ${body:-}${body:+ · }${lens}${film:+ 🎞️ }${film:-}

EOF } photo_info() { local photo=$1 ExposureTime= FNumber= FocalLength= PhotographicSensitivity= eval $( identify -format '%[EXIF:*]' $photo 2>/dev/null | grep -E 'ExposureTime|FNumber|FocalLength|PhotographicSensitivity' | sed 's/^exif://' ) } photo_id() { local photo=$1 photo=${photo##*/} photo=${photo%%.*} echo $photo } page_photo() { local photo=$1 preview=$2 description=$3 photo_info $photo cat <<-EOF
EOF if test -f $description; then cat <<-EOF $(encode $description) EOF else cat <<-EOF EOF fi cat <<-EOF
EOF if test -n "${ExposureTime}"; then cat <<-EOF ${ExposureTime} · ƒ/$(bc -S 1 -e ${FNumber}) · $(bc -e ${FocalLength}) mm · ${PhotographicSensitivity} ISO EOF fi if test -f $description; then cat <<-EOF
description $(encode $description)
EOF fi cat <<-EOF
EOF } index_head() { cat <<-EOF Photos EOF } index_page() { local date=$1 root=${2:-} cat <<-EOF

$(page_title $date)

EOF } index_photo() { local date=$1 photo=$2 thumbnail=$3 root=${4:-} cat <<-EOF EOF } Root=https://photo.causal.agency atom_head() { local updated=$(date -u '+%FT%TZ') cat <<-EOF Photos junejune@causal.agency ${Root}/ ${updated} EOF } atom_entry_head() { local date=$1 local updated=$( date -ju -f '%s' $(stat -f '%m' static/${date}/index.html) '+%FT%TZ' ) cat <<-EOF $(page_title $date) ${Root}/${date}/ ${updated} EOF } atom_entry_tail() { cat <<-EOF EOF } atom_tail() { cat <<-EOF EOF } set -- for date in 20*; do mkdir -p static/${date} page=static/${date}/index.html if ! test -f $page; then echo $page >&2 page_head $date >$page for photo in ${date}/*.[Jj][Pp][Gg]; do preview=$(preview $photo) if ! test -f static/${photo}; then ln $photo static/${photo} fi page_photo $photo $preview ${photo%.[Jj][Pp][Gg]}.txt >>$page done fi set -- $date "$@" done echo static/index.html >&2 index_head >static/index.html echo static/feed.atom >&2 atom_head >static/feed.atom for date; do index_page $date >>static/index.html atom_entry_head $date >>static/feed.atom for photo in ${date}/*.[Jj][Pp][Gg]; do thumbnail=$(thumbnail $photo) index_photo $date $photo $thumbnail >>static/index.html index_photo $date $photo $thumbnail $Root | encode >>static/feed.atom done atom_entry_tail >>static/feed.atom done atom_tail >>static/feed.atom