diff options
| author | Paul C. Buetow (mars.fritz.box) <paul@buetow.org> | 2014-05-07 14:38:28 +0200 |
|---|---|---|
| committer | Paul C. Buetow (mars.fritz.box) <paul@buetow.org> | 2014-05-07 14:38:28 +0200 |
| commit | 92eb329acc9e5b1905786d96be6fe151093c98ac (patch) | |
| tree | 43953a8876e69403ad199cf61b5f30f724d14783 | |
| parent | 31e2b7c8a9d4776f5443dfe0dcc0cd037a52d29a (diff) | |
can create album overview page
| -rw-r--r-- | share/templates/default/header.tmpl | 4 | ||||
| -rw-r--r-- | share/templates/default/index-preview.tmpl | 6 | ||||
| -rwxr-xr-x | src/photoalbum.sh | 41 |
3 files changed, 40 insertions, 11 deletions
diff --git a/share/templates/default/header.tmpl b/share/templates/default/header.tmpl index 3c0a2e7..0d9606a 100644 --- a/share/templates/default/header.tmpl +++ b/share/templates/default/header.tmpl @@ -1,5 +1,5 @@ -if [ "$IS_SUB" = yes ]; then - TOP="<br /><a href='${BACKHREF}/index.html'>Go to top</a>" +if [ "$IS_SUBALBUM" = yes ]; then + TOP="<br /><br /><a href='${BACKHREF}/index.html'>Go to Album overview</a>" fi cat <<END <html> diff --git a/share/templates/default/index-preview.tmpl b/share/templates/default/index-preview.tmpl new file mode 100644 index 0000000..909f59d --- /dev/null +++ b/share/templates/default/index-preview.tmpl @@ -0,0 +1,6 @@ +cat <<END +<h2>Album ${ALBUM}</h2> +<a name='${ALBUM}' href='${ALBUM}/index.html'> + <img border='0' src='${BACKHREF}/${RANDOM_THUMB}' /> +</a> +END diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 50211d5..13a8b95 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -32,7 +32,6 @@ function init() { } function clean() { - echo "Not deleting ${INCOMING_DIR} but ${DIST_DIR}" [ -d "${DIST_DIR}" ] && rm -Rf "${DIST_DIR}" } @@ -72,16 +71,20 @@ function generate() { find "${DIST_DIR}" -type f -name \*.html -delete # Figure out wether we want sub-albums or not + # TODO: Refactor, store dirs in a Bash Array dirs=$(find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | head | wc -l) if [[ "${SUB_ALBUMS}" != yes || ${dirs} -eq 0 ]]; then - makehtml photos html thumbs .. + makealbumhtml photos html thumbs .. else + IS_SUBALBUM=yes find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | while read dir; do basename=$(basename "${dir}") - makehtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" ../.. + makealbumhtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" ../.. done + # Create an album selection screen + makealbumoverviewhtml fi # Create top level index/redirect page @@ -97,7 +100,7 @@ function template() { local -r html=${1} ; shift local -r dist_html="${DIST_DIR}/${HTML_DIR}" - echo "Creating ${dist_html}/${html}.html from ${template}.tmpl" + #echo "Creating ${dist_html}/${html}.html from ${template}.tmpl" [ ! -d "${dist_html}" ] && mkdir -p "${dist_html}" source "${TEMPLATE_DIR}/${template}.tmpl" >> "${dist_html}/${html}.html" } @@ -115,13 +118,11 @@ function makescale() { echo "Scaling ${photo} to ${destphoto_nospace}" convert -auto-orient \ -geometry ${GEOMETRY} "${photo}" "${destphoto_nospace}" - else - echo "Not scaling ${photo} to ${destphoto_nospace}, already exists" fi done } -function makehtml() { +function makealbumhtml() { # First initialize some globals (used as template vars) PHOTOS_DIR="${1}" ; shift HTML_DIR="${1}" ; shift @@ -167,8 +168,6 @@ function makehtml() { [ ! -d "${dirname}" ] && mkdir -p "${dirname}" convert -geometry x${THUMBGEOMETRY} "${photo}" \ "${DIST_DIR}/${THUMBS_DIR}/${photo}" - else - echo "Not creating thumb ${DIST_DIR}/${THUMBS_DIR}/${photo}, already exists"; fi done @@ -201,10 +200,34 @@ function makehtml() { template redirect ${nextredirect} done + # Create per album index/redirect page REDIRECT_PAGE=page-1 template redirect index } +function makealbumoverviewhtml() { + HTML_DIR=html + BACKHREF=.. + IS_SUBALBUM=no + + template header index + template header-first-add index + + find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | sort | + while read dir; do + basename=$(basename "$dir") + ALBUM=$basename + thumbs_dir="${DIST_DIR}/thumbs/${basename}" + count=$(ls "${thumbs_dir}" | wc -l) + random=$(( 1 + $RANDOM % $count )) + RANDOM_THUMB="./thumbs/${basename}"/$(find "$thumbs_dir" -type f -printf "%f\n" | + head -n $random | tail -n 1) + template index-preview index + done + + template footer index +} + function makemake() { [ ! -f ./photoalbumrc ] && cp /etc/default/photoalbum ./photoalbumrc cat <<MAKEFILE > ./Makefile |
