From 13fd6a2b55e69ec81bfb77d657eaa3ab2f79d5fb Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 09:44:07 +0200 Subject: dont scale if destination already exists --- src/photoalbum.sh | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/photoalbum.sh b/src/photoalbum.sh index dc536b6..cc366e7 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -1,6 +1,6 @@ #!/bin/bash -# photoalbum (c) 2011 - 2014 by Paul Buetow +# photoalbum (c) 2011 - 2014 by Paul C. Buetow # http://photoalbum.buetow.org declare -r ARG1="${1}"; shift @@ -18,25 +18,25 @@ if [ ! -f "${RC}" ]; then exit 1 fi -usage() { +function usage() { cat - <&2 Usage: $0 clean|init|version|generate|all [rcfile] USAGE } -init() { +function init() { for dir in "${INCOMING_DIR}" "${DIST_DIR}/photos" "${DIST_DIR}/thumbs" "${DIST_DIR}/html"; do [ -d "${dir}" ] || mkdir -vp "${dir}" done } -clean() { +function clean() { echo "Not deleting ${INCOMING_DIR}" [ -d "${DIST_DIR}" ] && rm -Rf "${DIST_DIR}" } -tarball() { +function tarball() { # Cleanup tarball from prev run if any find "${DIST_DIR}" -maxdepth 1 -type f -name \*.tar -delete @@ -50,7 +50,7 @@ tarball() { fi } -generate() { +function generate() { if [ ! -d "${INCOMING_DIR}" ]; then echo "ERROR: You may run init first, no such directory: ${INCOMING_DIR}" >&2 exit 1 @@ -74,14 +74,14 @@ generate() { tarball } -template() { +function template() { local -r template=${1} ; shift local -r html=${1} ; shift source "${TEMPLATE_DIR}/${template}.tmpl" >> "${DIST_DIR}/html/${html}.html" } -scale() { +function scale() { cd "${INCOMING_DIR}" && find ./ -type f | sort | while read photo; do photo=$(sed 's#^\./##' <<< "${photo}") @@ -93,10 +93,18 @@ scale() { destphoto="${photo}" fi - echo "Scaling ${photo} to ${DIST_DIR}/photos/${destphoto}" - convert -auto-orient \ - -geometry ${GEOMETRY} "${photo}" "${DIST_DIR}/photos/${destphoto}" + destphoto_flatten=${destphoto// /_} + if [[ ! -f "${DIST_DIR}/photos/${destphoto}" + && ! -f "${DIST_DIR}/photos/${destphoto_flatten}" ]]; then + + echo "Scaling ${photo} to ${DIST_DIR}/photos/${destphoto}" + + convert -auto-orient \ + -geometry ${GEOMETRY} "${photo}" "${DIST_DIR}/photos/${destphoto}" + else + echo "Not scaling ${photo}, destination already exists" + fi fi done @@ -106,7 +114,7 @@ scale() { done } -makedist() { +function makedist() { local num=${1} ; shift local name=page-${num} local -i i=0 -- cgit v1.2.3 From e2b02d5f773a6d0d3523ce5ea9c64605b9257a40 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 09:54:59 +0200 Subject: some enhancements --- src/photoalbum.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/photoalbum.sh b/src/photoalbum.sh index cc366e7..034a518 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -93,10 +93,10 @@ function scale() { destphoto="${photo}" fi + destphoto_nospace=${destphoto// /_} - destphoto_flatten=${destphoto// /_} if [[ ! -f "${DIST_DIR}/photos/${destphoto}" - && ! -f "${DIST_DIR}/photos/${destphoto_flatten}" ]]; then + && ! -f "${DIST_DIR}/photos/${destphoto_nospace}" ]]; then echo "Scaling ${photo} to ${DIST_DIR}/photos/${destphoto}" -- cgit v1.2.3 From 4ca143713c90a020fa3a3864f3d7acbdfe7c42cf Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 10:14:17 +0200 Subject: add makemake --- docs/photoalbum.1 | 6 +++++- docs/photoalbum.pod | 5 +++++ docs/photoalbum.txt | 6 +++++- src/photoalbum.sh | 16 ++++++++++++++-- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/docs/photoalbum.1 b/docs/photoalbum.1 index c518477..5544689 100644 --- a/docs/photoalbum.1 +++ b/docs/photoalbum.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "PHOTOALBUM 1" -.TH PHOTOALBUM 1 "2014-02-16" "photoalbum 0.3.0" "User Commands" +.TH PHOTOALBUM 1 "2014-05-07" "photoalbum 0.3.0" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -134,6 +134,7 @@ photoalbum \- photoalbum is a minimal bash script for linux to generate static w .SH "SYNOPSIS" .IX Header "SYNOPSIS" photoalbum clean|init|version|generate|all [rcfile] +photoalbum makemake .IP "clean" 4 .IX Item "clean" Cleans up the working space @@ -149,6 +150,9 @@ Generates the static photoalbum .IP "all" 4 .IX Item "all" This just runs 'clean init generate' right after another. +.IP "makemake" 4 +.IX Item "makemake" +Creates a Makefile and photoalbumrc in the current working directory. .SS "\s-1RCFILE\s0" .IX Subsection "RCFILE" .SS "\s-1TUTORIAL\s0" diff --git a/docs/photoalbum.pod b/docs/photoalbum.pod index 791de48..914708d 100644 --- a/docs/photoalbum.pod +++ b/docs/photoalbum.pod @@ -5,6 +5,7 @@ photoalbum - photoalbum is a minimal bash script for linux to generate static we =head1 SYNOPSIS photoalbum clean|init|version|generate|all [rcfile] +photoalbum makemake =over @@ -28,6 +29,10 @@ Generates the static photoalbum This just runs 'clean init generate' right after another. +=item makemake + +Creates a Makefile and photoalbumrc in the current working directory. + =back =head2 RCFILE diff --git a/docs/photoalbum.txt b/docs/photoalbum.txt index fbb2d32..32722a7 100644 --- a/docs/photoalbum.txt +++ b/docs/photoalbum.txt @@ -3,7 +3,7 @@ NAME static web photo albums. SYNOPSIS - photoalbum clean|init|version|generate|all [rcfile] + photoalbum clean|init|version|generate|all [rcfile] photoalbum makemake clean Cleans up the working space @@ -19,6 +19,10 @@ SYNOPSIS all This just runs 'clean init generate' right after another. + makemake + Creates a Makefile and photoalbumrc in the current working + directory. + RCFILE TUTORIAL * See if /etc/default/photoalbum fits your needs. If not, copy diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 034a518..e467aeb 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -32,7 +32,7 @@ function init() { } function clean() { - echo "Not deleting ${INCOMING_DIR}" + echo "Not deleting ${INCOMING_DIR} but ${DIST_DIR}" [ -d "${DIST_DIR}" ] && rm -Rf "${DIST_DIR}" } @@ -184,6 +184,16 @@ function makedist() { done } +function makemake() { + [ ! -f ./photoalbumrc ] && cp /etc/default/photoalbum ./photoalbumrc + cat < ./Makefile +all: + photoalbum all photoalbumrc +clean: + photoalbum clean photoalbumrc +MAKEFILE +} + source "${RC}" if [ -f ~/.photoalbumrc ]; then @@ -192,7 +202,6 @@ fi case "${ARG1}" in all) - clean init generate ;; @@ -208,6 +217,9 @@ case "${ARG1}" in version) echo "This is Photoalbum Version ${VERSION}" ;; + makemake) + makemake + ;; *) usage ;; -- cgit v1.2.3 From 15e73417d066343b721b1c07e8b73a1abe17f28b Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 11:02:41 +0200 Subject: sub-directories are not flatten anymore --- src/photoalbum.sh | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/src/photoalbum.sh b/src/photoalbum.sh index e467aeb..fda18e1 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -3,12 +3,12 @@ # photoalbum (c) 2011 - 2014 by Paul C. Buetow # http://photoalbum.buetow.org -declare -r ARG1="${1}"; shift -declare RC="${1}" ; shift - declare -r VERSION='PHOTOALBUMVERSION' declare -r DEFAULTRC=/etc/default/photoalbum +declare -r ARG1="${1}" ; shift +declare RC="${1}" ; shift + if [ -z "${RC}" ]; then RC="${DEFAULTRC}" fi @@ -84,34 +84,20 @@ function template() { function scale() { cd "${INCOMING_DIR}" && find ./ -type f | sort | while read photo; do photo=$(sed 's#^\./##' <<< "${photo}") + destphoto="${DIST_DIR}/photos/${photo}" + destphoto_nospace=${destphoto// /_} - if [ ! -f "${DIST_DIR}/photos/${photo}" ]; then - # Flatten directories / to __ - if [[ "${photo}" =~ / ]]; then - destphoto="${photo//\//__}" - else - destphoto="${photo}" - fi - - destphoto_nospace=${destphoto// /_} - - if [[ ! -f "${DIST_DIR}/photos/${destphoto}" - && ! -f "${DIST_DIR}/photos/${destphoto_nospace}" ]]; then + dirname=$(dirname "${destphoto}") + [ ! -d "${dirname}" ] && mkdir -p "${dirname}" - echo "Scaling ${photo} to ${DIST_DIR}/photos/${destphoto}" - - convert -auto-orient \ - -geometry ${GEOMETRY} "${photo}" "${DIST_DIR}/photos/${destphoto}" - else - echo "Not scaling ${photo}, destination already exists" - fi + if [ ! -f "${destphoto_nospace}" ]; then + 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 - - echo 'Removing spaces from file names' - find "${DIST_DIR}/photos" -type f -name '* *' | while read file; do - rename 's/ /_/g' "${file}" - done } function makedist() { @@ -150,6 +136,8 @@ function makedist() { if [ ! -f "${DIST_DIR}/thumbs/${photo}" ]; then echo "Creating thumb for ${photo}"; + dirname=$(dirname "${DIST_DIR}/thumbs/${photo}") + [ ! -d "${dirname}" ] && mkdir -p "${dirname}" convert -geometry x${THUMBGEOMETRY} "${photo}" \ "${DIST_DIR}/thumbs/${photo}" fi -- cgit v1.2.3 From efa7f66884c81fdf404a839bd89ed70b69453df1 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 11:08:45 +0200 Subject: Hell is empty and all the devils are here. -- Wm. Shakespeare, "The Tempest" --- src/photoalbum.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/photoalbum.sh b/src/photoalbum.sh index fda18e1..3d90052 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -67,9 +67,9 @@ function generate() { TARBALL_NAME="${BASE}-${NOW}${TARBALL_SUFFIX}" fi - scale + makescale find "${DIST_DIR}/html" -type f -name \*.html -delete - makedist 1 + makehtml 1 template index ../index tarball } @@ -81,7 +81,7 @@ function template() { source "${TEMPLATE_DIR}/${template}.tmpl" >> "${DIST_DIR}/html/${html}.html" } -function scale() { +function makescale() { cd "${INCOMING_DIR}" && find ./ -type f | sort | while read photo; do photo=$(sed 's#^\./##' <<< "${photo}") destphoto="${DIST_DIR}/photos/${photo}" @@ -100,7 +100,7 @@ function scale() { done } -function makedist() { +function makehtml() { local num=${1} ; shift local name=page-${num} local -i i=0 @@ -180,6 +180,7 @@ all: clean: photoalbum clean photoalbumrc MAKEFILE + echo You may now customize ./photoalbumrc and run make } source "${RC}" -- cgit v1.2.3 From fc5a23185523e67d9d3b6dc08dc692898823d258 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 11:21:53 +0200 Subject: refactor makehtml --- src/photoalbum.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 3d90052..6180571 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -69,7 +69,7 @@ function generate() { makescale find "${DIST_DIR}/html" -type f -name \*.html -delete - makehtml 1 + makehtml "${DIST_DIR}/photos" "${DIST_DIR}/html" template index ../index tarball } @@ -101,14 +101,16 @@ function makescale() { } function makehtml() { - local num=${1} ; shift - local name=page-${num} + local dist_photo="${1}" ; shift + local dist_html="${1}" ; shift + local -i num=1 local -i i=0 + local name=page-${num} template header ${name} template header-first-add ${name} - cd "${DIST_DIR}/photos" && find ./ -type f | sort | sed 's;^\./;;' | + cd "${dist_photo}" && find ./ -type f | sort | sed 's;^\./;;' | while read photo; do : $(( i++ )) @@ -140,12 +142,14 @@ function makehtml() { [ ! -d "${dirname}" ] && mkdir -p "${dirname}" convert -geometry x${THUMBGEOMETRY} "${photo}" \ "${DIST_DIR}/thumbs/${photo}" + else + echo "Not creating thumb for ${photo}, already exists"; fi done template footer $(cd "${DIST_DIR}/html";ls -t page-*.html | head -n 1 | sed 's/.html//') - cd "${DIST_DIR}/html" && ls *.html | grep -v page- | cut -d'-' -f1 | uniq | + cd "${dist_html}" && ls *.html | grep -v page- | cut -d'-' -f1 | uniq | while read prefix; do declare page=$(ls -t ${prefix}-*.html | head -n 1 | sed 's#\(.*\)-.*.html#\1#') -- cgit v1.2.3 From d39d8c4c71a413003ed396607875fbe4c70a2f5f Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 13:06:29 +0200 Subject: can create sub albums --- share/templates/default/footer.tmpl | 4 +- share/templates/default/header.tmpl | 31 +++++----- share/templates/default/index.tmpl | 2 +- share/templates/default/preview.tmpl | 4 +- share/templates/default/view.tmpl | 6 +- share/templates/minimal/footer.tmpl | 4 -- share/templates/minimal/header-first-add.tmpl | 3 - share/templates/minimal/header.tmpl | 22 ------- share/templates/minimal/index.tmpl | 12 ---- share/templates/minimal/next.tmpl | 4 -- share/templates/minimal/prev.tmpl | 3 - share/templates/minimal/preview.tmpl | 3 - share/templates/minimal/redirect.tmpl | 9 --- share/templates/minimal/view.tmpl | 3 - src/photoalbum.sh | 84 +++++++++++++++++---------- 15 files changed, 80 insertions(+), 114 deletions(-) delete mode 100644 share/templates/minimal/footer.tmpl delete mode 100644 share/templates/minimal/header-first-add.tmpl delete mode 100644 share/templates/minimal/header.tmpl delete mode 100644 share/templates/minimal/index.tmpl delete mode 100644 share/templates/minimal/next.tmpl delete mode 100644 share/templates/minimal/prev.tmpl delete mode 100644 share/templates/minimal/preview.tmpl delete mode 100644 share/templates/minimal/redirect.tmpl delete mode 100644 share/templates/minimal/view.tmpl diff --git a/share/templates/default/footer.tmpl b/share/templates/default/footer.tmpl index 0de72ce..18e3512 100644 --- a/share/templates/default/footer.tmpl +++ b/share/templates/default/footer.tmpl @@ -5,12 +5,12 @@ END if [ "${TARBALL_INCLUDE}" = 'yes' ]; then cat <here

+Download all photos in original size here

END fi cat < END diff --git a/share/templates/default/header.tmpl b/share/templates/default/header.tmpl index b21a200..3c0a2e7 100644 --- a/share/templates/default/header.tmpl +++ b/share/templates/default/header.tmpl @@ -1,24 +1,27 @@ +if [ "$IS_SUB" = yes ]; then + TOP="
Go to top" +fi cat < $TITLE -$TITLE +$TITLE $TOP
END diff --git a/share/templates/default/index.tmpl b/share/templates/default/index.tmpl index 2ec99d7..ecfb9f6 100644 --- a/share/templates/default/index.tmpl +++ b/share/templates/default/index.tmpl @@ -3,7 +3,7 @@ cat < $TITLE - + Redirecting to Page 1 diff --git a/share/templates/default/preview.tmpl b/share/templates/default/preview.tmpl index a5e4bdc..646fc5c 100644 --- a/share/templates/default/preview.tmpl +++ b/share/templates/default/preview.tmpl @@ -1,3 +1,5 @@ cat < + + + END diff --git a/share/templates/default/view.tmpl b/share/templates/default/view.tmpl index abf577a..43930de 100644 --- a/share/templates/default/view.tmpl +++ b/share/templates/default/view.tmpl @@ -4,9 +4,11 @@ cat <>>>

- + + +

-Direct link +Direct link

$photo

END diff --git a/share/templates/minimal/footer.tmpl b/share/templates/minimal/footer.tmpl deleted file mode 100644 index 6473552..0000000 --- a/share/templates/minimal/footer.tmpl +++ /dev/null @@ -1,4 +0,0 @@ -cat < - -END diff --git a/share/templates/minimal/header-first-add.tmpl b/share/templates/minimal/header-first-add.tmpl deleted file mode 100644 index f11a346..0000000 --- a/share/templates/minimal/header-first-add.tmpl +++ /dev/null @@ -1,3 +0,0 @@ -cat < -END diff --git a/share/templates/minimal/header.tmpl b/share/templates/minimal/header.tmpl deleted file mode 100644 index 8b20b53..0000000 --- a/share/templates/minimal/header.tmpl +++ /dev/null @@ -1,22 +0,0 @@ -cat < - -$TITLE - - - -END diff --git a/share/templates/minimal/index.tmpl b/share/templates/minimal/index.tmpl deleted file mode 100644 index 2ec99d7..0000000 --- a/share/templates/minimal/index.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -cat < - -$TITLE - - - - -Redirecting to Page 1 - - -END diff --git a/share/templates/minimal/next.tmpl b/share/templates/minimal/next.tmpl deleted file mode 100644 index a7f7c76..0000000 --- a/share/templates/minimal/next.tmpl +++ /dev/null @@ -1,4 +0,0 @@ -cat < -Next $MAXPREVIEWS pictures -END diff --git a/share/templates/minimal/prev.tmpl b/share/templates/minimal/prev.tmpl deleted file mode 100644 index 64d15d8..0000000 --- a/share/templates/minimal/prev.tmpl +++ /dev/null @@ -1,3 +0,0 @@ -cat <Previous $MAXPREVIEWS pictures -END diff --git a/share/templates/minimal/preview.tmpl b/share/templates/minimal/preview.tmpl deleted file mode 100644 index a5e4bdc..0000000 --- a/share/templates/minimal/preview.tmpl +++ /dev/null @@ -1,3 +0,0 @@ -cat < -END diff --git a/share/templates/minimal/redirect.tmpl b/share/templates/minimal/redirect.tmpl deleted file mode 100644 index 8edfe1c..0000000 --- a/share/templates/minimal/redirect.tmpl +++ /dev/null @@ -1,9 +0,0 @@ -cat < - - - - - - -END diff --git a/share/templates/minimal/view.tmpl b/share/templates/minimal/view.tmpl deleted file mode 100644 index c93a82b..0000000 --- a/share/templates/minimal/view.tmpl +++ /dev/null @@ -1,3 +0,0 @@ -cat < -END diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 6180571..b639b6b 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -69,16 +69,28 @@ function generate() { makescale find "${DIST_DIR}/html" -type f -name \*.html -delete - makehtml "${DIST_DIR}/photos" "${DIST_DIR}/html" - template index ../index + + # Figure out wether we want sub-albums or not + dirs=$(find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | head | wc -l) + if [ ${dirs} -eq 0 ]; then + makehtml photos html thumbs .. + else + find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | + while read dir; do + basename=$(basename "${dir}") + makehtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" ../.. + done + fi tarball } function template() { - local -r template=${1} ; shift - local -r html=${1} ; shift + local -r template=${1} ; shift + local -r html=${1} ; shift + local -r dist_html=${1} ; shift - source "${TEMPLATE_DIR}/${template}.tmpl" >> "${DIST_DIR}/html/${html}.html" + echo "Creating ${dist_html}/${html}.html from ${template}.tmpl" + source "${TEMPLATE_DIR}/${template}.tmpl" >> "${dist_html}/${html}.html" } function makescale() { @@ -101,16 +113,21 @@ function makescale() { } function makehtml() { - local dist_photo="${1}" ; shift - local dist_html="${1}" ; shift + PHOTOS_DIR="${1}" ; shift + HTML_DIR="${1}" ; shift + THUMBS_DIR="${1}"; shift + BACKHREF="${1}" ; shift + local -r dist_html="${DIST_DIR}/${HTML_DIR}" local -i num=1 local -i i=0 local name=page-${num} - template header ${name} - template header-first-add ${name} + [ ! -d "${dist_html}" ] && mkdir -p "${dist_html}" + + template header ${name} "${dist_html}" + template header-first-add ${name} "${dist_html}" - cd "${dist_photo}" && find ./ -type f | sort | sed 's;^\./;;' | + cd "${DIST_DIR}/${PHOTOS_DIR}" && find ./ -type f | sort | sed 's;^\./;;' | while read photo; do : $(( i++ )) @@ -119,35 +136,36 @@ function makehtml() { : $(( num++ )) next=page-${num} - template next ${name} - template footer ${name} + template next ${name} "${dist_html}" + template footer ${name} "${dist_html}" prev=${name} name=${next} - template header ${name} - template prev ${name} + template header ${name} "${dist_html}" + template prev ${name} "${dist_html}" fi # Preview page - template preview ${name} + template preview ${name} "${dist_html}" # View page - template header ${num}-${i} - template view ${num}-${i} - template footer ${num}-${i} + template header ${num}-${i} "${dist_html}" + template view ${num}-${i} "${dist_html}" + template footer ${num}-${i} "${dist_html}" - if [ ! -f "${DIST_DIR}/thumbs/${photo}" ]; then - echo "Creating thumb for ${photo}"; - dirname=$(dirname "${DIST_DIR}/thumbs/${photo}") + if [ ! -f "${DIST_DIR}/${THUMBS_DIR}/${photo}" ]; then + echo "Creating thumb ${DIST_DIR}/${THUMBS_DIR}/${photo}"; + dirname=$(dirname "${DIST_DIR}/${THUMBS_DIR}/${photo}") [ ! -d "${dirname}" ] && mkdir -p "${dirname}" convert -geometry x${THUMBGEOMETRY} "${photo}" \ - "${DIST_DIR}/thumbs/${photo}" + "${DIST_DIR}/${THUMBS_DIR}/${photo}" else - echo "Not creating thumb for ${photo}, already exists"; + echo "Not creating thumb ${DIST_DIR}/${THUMBS_DIR}/${photo}, already exists"; fi done - template footer $(cd "${DIST_DIR}/html";ls -t page-*.html | head -n 1 | sed 's/.html//') + template footer $(cd "${dist_html}";ls -t page-*.html | + head -n 1 | sed 's/.html//') "${dist_html}" cd "${dist_html}" && ls *.html | grep -v page- | cut -d'-' -f1 | uniq | while read prefix; do @@ -161,19 +179,21 @@ function makehtml() { declare nextredirect=${page}-$((lastview+1)) redirectpage=$(( page-1 ))-${MAXPREVIEWS} - template redirect ${prevredirect} + template redirect ${prevredirect} "${dist_html}" if [ ${lastview} -eq ${MAXPREVIEWS} ]; then redirectpage=$(( page+1 ))-1 else redirectpage=${page}-${lastview} - template redirect 0-${MAXPREVIEWS} + template redirect 0-${MAXPREVIEWS} "${dist_html}" redirectpage=1-1 fi - template redirect ${nextredirect} + template redirect ${nextredirect} "${dist_html}" done + + template index ../index "${dist_html}" } function makemake() { @@ -187,10 +207,12 @@ MAKEFILE echo You may now customize ./photoalbumrc and run make } -source "${RC}" - -if [ -f ~/.photoalbumrc ]; then - source ~/.photoalbumrc +if [ -f "${RC}" ]; then + source "${RC}" +else + if [ -f ~/.photoalbumrc ]; then + source ~/.photoalbumrc + fi fi case "${ARG1}" in -- cgit v1.2.3 From bc94071935a1bb072fc665798c6ec9c0b41d6222 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 13:13:10 +0200 Subject: refactor --- src/photoalbum.sh | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/photoalbum.sh b/src/photoalbum.sh index b639b6b..6099e5e 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -87,9 +87,10 @@ function generate() { function template() { local -r template=${1} ; shift local -r html=${1} ; shift - local -r dist_html=${1} ; shift + local -r dist_html="${DIST_DIR}/${HTML_DIR}" 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" } @@ -114,18 +115,16 @@ function makescale() { function makehtml() { PHOTOS_DIR="${1}" ; shift - HTML_DIR="${1}" ; shift - THUMBS_DIR="${1}"; shift - BACKHREF="${1}" ; shift - local -r dist_html="${DIST_DIR}/${HTML_DIR}" + HTML_DIR="${1}" ; shift + THUMBS_DIR="${1}" ; shift + BACKHREF="${1}" ; shift + local -i num=1 local -i i=0 local name=page-${num} - [ ! -d "${dist_html}" ] && mkdir -p "${dist_html}" - - template header ${name} "${dist_html}" - template header-first-add ${name} "${dist_html}" + template header ${name} + template header-first-add ${name} cd "${DIST_DIR}/${PHOTOS_DIR}" && find ./ -type f | sort | sed 's;^\./;;' | while read photo; do @@ -136,22 +135,22 @@ function makehtml() { : $(( num++ )) next=page-${num} - template next ${name} "${dist_html}" - template footer ${name} "${dist_html}" + template next ${name} + template footer ${name} prev=${name} name=${next} - template header ${name} "${dist_html}" - template prev ${name} "${dist_html}" + template header ${name} + template prev ${name} fi # Preview page - template preview ${name} "${dist_html}" + template preview ${name} # View page - template header ${num}-${i} "${dist_html}" - template view ${num}-${i} "${dist_html}" - template footer ${num}-${i} "${dist_html}" + template header ${num}-${i} + template view ${num}-${i} + template footer ${num}-${i} if [ ! -f "${DIST_DIR}/${THUMBS_DIR}/${photo}" ]; then echo "Creating thumb ${DIST_DIR}/${THUMBS_DIR}/${photo}"; @@ -164,10 +163,10 @@ function makehtml() { fi done - template footer $(cd "${dist_html}";ls -t page-*.html | - head -n 1 | sed 's/.html//') "${dist_html}" + template footer $(cd "${DIST_DIR}/${HTML_DIR}";ls -t page-*.html | + head -n 1 | sed 's/.html//') "${DIST_DIR}/${HTML_DIR}" - cd "${dist_html}" && ls *.html | grep -v page- | cut -d'-' -f1 | uniq | + cd "${DIST_DIR}/${HTML_DIR}" && ls *.html | grep -v page- | cut -d'-' -f1 | uniq | while read prefix; do declare page=$(ls -t ${prefix}-*.html | head -n 1 | sed 's#\(.*\)-.*.html#\1#') @@ -179,21 +178,21 @@ function makehtml() { declare nextredirect=${page}-$((lastview+1)) redirectpage=$(( page-1 ))-${MAXPREVIEWS} - template redirect ${prevredirect} "${dist_html}" + template redirect ${prevredirect} if [ ${lastview} -eq ${MAXPREVIEWS} ]; then redirectpage=$(( page+1 ))-1 else redirectpage=${page}-${lastview} - template redirect 0-${MAXPREVIEWS} "${dist_html}" + template redirect 0-${MAXPREVIEWS} redirectpage=1-1 fi - template redirect ${nextredirect} "${dist_html}" + template redirect ${nextredirect} done - template index ../index "${dist_html}" + template index ../index } function makemake() { -- cgit v1.2.3 From 14731e9c43403f0961b086920bd331235487ce50 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 13:16:26 +0200 Subject: can enable and disable sub-albums --- src/photoalbum.default.conf | 2 ++ src/photoalbum.sh | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/photoalbum.default.conf b/src/photoalbum.default.conf index 2a85fc7..160a8ed 100644 --- a/src/photoalbum.default.conf +++ b/src/photoalbum.default.conf @@ -8,6 +8,8 @@ MAXPREVIEWS=100 # Diverse directories, need to be full paths, not relative! INCOMING_DIR=$(pwd)/incoming +# Set to yes if per directory sub-albums are wanted +SUB_ALBUMS=no DIST_DIR=$(pwd)/dist TEMPLATE_DIR=/usr/share/photoalbum/templates/default #TEMPLATE_DIR=/usr/share/photoalbum/templates/minimal diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 6099e5e..8334872 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -72,7 +72,7 @@ function generate() { # Figure out wether we want sub-albums or not dirs=$(find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | head | wc -l) - if [ ${dirs} -eq 0 ]; then + if [[ "${SUB_ALBUMS}" != yes || ${dirs} -eq 0 ]]; then makehtml photos html thumbs .. else find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | -- cgit v1.2.3 From 31e2b7c8a9d4776f5443dfe0dcc0cd037a52d29a Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 13:45:18 +0200 Subject: create index.html files correctly --- share/templates/default/index.tmpl | 12 ------------ share/templates/default/redirect.tmpl | 2 +- src/photoalbum.sh | 22 ++++++++++++++++------ 3 files changed, 17 insertions(+), 19 deletions(-) delete mode 100644 share/templates/default/index.tmpl diff --git a/share/templates/default/index.tmpl b/share/templates/default/index.tmpl deleted file mode 100644 index ecfb9f6..0000000 --- a/share/templates/default/index.tmpl +++ /dev/null @@ -1,12 +0,0 @@ -cat < - -$TITLE - - - - -Redirecting to Page 1 - - -END diff --git a/share/templates/default/redirect.tmpl b/share/templates/default/redirect.tmpl index 8edfe1c..8353e7b 100644 --- a/share/templates/default/redirect.tmpl +++ b/share/templates/default/redirect.tmpl @@ -1,7 +1,7 @@ cat < - + diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 8334872..50211d5 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -55,6 +55,7 @@ function generate() { echo "ERROR: You may run init first, no such directory: ${INCOMING_DIR}" >&2 exit 1 fi + if [ ! -d "${DIST_DIR}" ]; then echo "ERROR: You may run init first, no such directory: ${DIST_DIR}" >&2 exit 1 @@ -68,12 +69,13 @@ function generate() { fi makescale - find "${DIST_DIR}/html" -type f -name \*.html -delete + find "${DIST_DIR}" -type f -name \*.html -delete # Figure out wether we want sub-albums or not 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 .. + else find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | while read dir; do @@ -81,6 +83,12 @@ function generate() { makehtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" ../.. done fi + + # Create top level index/redirect page + HTML_DIR=./ + REDIRECT_PAGE=./html/index + template redirect index + tarball } @@ -114,6 +122,7 @@ function makescale() { } function makehtml() { + # First initialize some globals (used as template vars) PHOTOS_DIR="${1}" ; shift HTML_DIR="${1}" ; shift THUMBS_DIR="${1}" ; shift @@ -177,22 +186,23 @@ function makehtml() { declare prevredirect=${page}-0 declare nextredirect=${page}-$((lastview+1)) - redirectpage=$(( page-1 ))-${MAXPREVIEWS} + REDIRECT_PAGE=$(( page-1 ))-${MAXPREVIEWS} template redirect ${prevredirect} if [ ${lastview} -eq ${MAXPREVIEWS} ]; then - redirectpage=$(( page+1 ))-1 + REDIRECT_PAGE=$(( page+1 ))-1 else - redirectpage=${page}-${lastview} + REDIRECT_PAGE=${page}-${lastview} template redirect 0-${MAXPREVIEWS} - redirectpage=1-1 + REDIRECT_PAGE=1-1 fi template redirect ${nextredirect} done - template index ../index + REDIRECT_PAGE=page-1 + template redirect index } function makemake() { -- cgit v1.2.3 From 92eb329acc9e5b1905786d96be6fe151093c98ac Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 14:38:28 +0200 Subject: can create album overview page --- share/templates/default/header.tmpl | 4 +-- share/templates/default/index-preview.tmpl | 6 +++++ src/photoalbum.sh | 41 +++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 share/templates/default/index-preview.tmpl 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="
Go to top" +if [ "$IS_SUBALBUM" = yes ]; then + TOP="

Go to Album overview" fi cat < 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 <Album ${ALBUM} + + + +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 -- cgit v1.2.3 From 9ed5d1e65a07ec1511a6599946b39c70f6441015 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Wed, 7 May 2014 14:58:35 +0200 Subject: more infos --- share/templates/default/header-first-add.tmpl | 2 +- share/templates/default/header.tmpl | 8 ++++---- share/templates/default/index-preview.tmpl | 2 +- share/templates/default/next.tmpl | 2 +- share/templates/default/prev.tmpl | 2 +- src/photoalbum.sh | 7 +++++-- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/share/templates/default/header-first-add.tmpl b/share/templates/default/header-first-add.tmpl index c6eed3a..f11a346 100644 --- a/share/templates/default/header-first-add.tmpl +++ b/share/templates/default/header-first-add.tmpl @@ -1,3 +1,3 @@ cat < +

END diff --git a/share/templates/default/header.tmpl b/share/templates/default/header.tmpl index 0d9606a..7d8e5a8 100644 --- a/share/templates/default/header.tmpl +++ b/share/templates/default/header.tmpl @@ -1,10 +1,10 @@ -if [ "$IS_SUBALBUM" = yes ]; then - TOP="

Go to Album overview" +if [ "${IS_SUBALBUM}" = yes ]; then + GOTO_OVERVIEW="

Go to Album overview" fi cat < -$TITLE +${TITLE} -$TITLE $TOP +${TITLE} ${GOTO_OVERVIEW}


END diff --git a/share/templates/default/index-preview.tmpl b/share/templates/default/index-preview.tmpl index 909f59d..6a5dbc5 100644 --- a/share/templates/default/index-preview.tmpl +++ b/share/templates/default/index-preview.tmpl @@ -1,5 +1,5 @@ cat <Album ${ALBUM} +

Album ${ALBUM} (${DESCRIPTION})

diff --git a/share/templates/default/next.tmpl b/share/templates/default/next.tmpl index a7f7c76..603ed0f 100644 --- a/share/templates/default/next.tmpl +++ b/share/templates/default/next.tmpl @@ -1,4 +1,4 @@ cat < -Next $MAXPREVIEWS pictures +Next $MAXPREVIEWS pictures of current Album END diff --git a/share/templates/default/prev.tmpl b/share/templates/default/prev.tmpl index bdabae2..d274bcb 100644 --- a/share/templates/default/prev.tmpl +++ b/share/templates/default/prev.tmpl @@ -1,4 +1,4 @@ cat <Previous $MAXPREVIEWS pictures +Previous $MAXPREVIEWS pictures of current Album

END diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 13a8b95..4e67bc0 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -218,10 +218,13 @@ function makealbumoverviewhtml() { basename=$(basename "$dir") ALBUM=$basename thumbs_dir="${DIST_DIR}/thumbs/${basename}" - count=$(ls "${thumbs_dir}" | wc -l) - random=$(( 1 + $RANDOM % $count )) + pictures=$(ls "${thumbs_dir}" | wc -l) + random=$(( 1 + $RANDOM % $pictures )) RANDOM_THUMB="./thumbs/${basename}"/$(find "$thumbs_dir" -type f -printf "%f\n" | head -n $random | tail -n 1) + pages=$(( $pictures / $MAXPREVIEWS + 1)) + test $pages -gt 1 && s=s || s='' + DESCRIPTION="${pictures} pictures / ${pages} page$s" template index-preview index done -- cgit v1.2.3 From 8966330880e0d6aa1ad59ae4599b0dfd3fb425b2 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Fri, 9 May 2014 09:36:27 +0200 Subject: refactor --- .version | 2 +- debian/changelog | 6 ++++++ docs/photoalbum.1 | 2 +- src/photoalbum.sh | 13 +++++-------- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.version b/.version index 0d91a54..896a713 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -0.3.0 +0.3.1develop diff --git a/debian/changelog b/debian/changelog index 35267b3..9a72189 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +photoalbum (0.3.1develop) stable; urgency=low + + * Dev version + + -- Paul Buetow Wed, 07 May 2014 14:58:51 +0200 + photoalbum (0.3.0) stable; urgency=low * Add another template set: minimal diff --git a/docs/photoalbum.1 b/docs/photoalbum.1 index 5544689..130a5c4 100644 --- a/docs/photoalbum.1 +++ b/docs/photoalbum.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "PHOTOALBUM 1" -.TH PHOTOALBUM 1 "2014-05-07" "photoalbum 0.3.0" "User Commands" +.TH PHOTOALBUM 1 "2014-05-07" "photoalbum 0.3.1develop" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 4e67bc0..3e9b61d 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -3,7 +3,7 @@ # photoalbum (c) 2011 - 2014 by Paul C. Buetow # http://photoalbum.buetow.org -declare -r VERSION='PHOTOALBUMVERSION' +declare -r VERSION='0.3.1develop' declare -r DEFAULTRC=/etc/default/photoalbum declare -r ARG1="${1}" ; shift @@ -69,22 +69,20 @@ function generate() { makescale find "${DIST_DIR}" -type f -name \*.html -delete + dirs=( $(find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | sort) ) # 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 + if [[ "${SUB_ALBUMS}" != yes || ${#dirs[*]} -eq 0 ]]; then makealbumhtml photos html thumbs .. else IS_SUBALBUM=yes - find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | - while read dir; do + for dir in ${dirs[*]}; do basename=$(basename "${dir}") makealbumhtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" ../.. done # Create an album selection screen - makealbumoverviewhtml + makealbumoverviewhtml <<< ${dirs[*]} fi # Create top level index/redirect page @@ -213,7 +211,6 @@ function makealbumoverviewhtml() { 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 -- cgit v1.2.3 From cd3e338ef309f389adef386b8ece02f919d01693 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Fri, 9 May 2014 10:15:23 +0200 Subject: refactor --- docs/photoalbum.pod | 10 +- share/templates/default/footer.tmpl | 2 +- share/templates/default/header-first-add.tmpl | 2 +- share/templates/default/header.tmpl | 5 +- share/templates/default/index-preview.tmpl | 6 +- share/templates/default/next.tmpl | 2 +- share/templates/default/prev.tmpl | 2 +- share/templates/default/preview.tmpl | 4 +- share/templates/default/redirect.tmpl | 2 +- share/templates/default/view.tmpl | 6 +- src/photoalbum.sh | 160 +++++++++++--------------- 11 files changed, 85 insertions(+), 116 deletions(-) diff --git a/docs/photoalbum.pod b/docs/photoalbum.pod index 914708d..e265954 100644 --- a/docs/photoalbum.pod +++ b/docs/photoalbum.pod @@ -4,7 +4,7 @@ photoalbum - photoalbum is a minimal bash script for linux to generate static we =head1 SYNOPSIS -photoalbum clean|init|version|generate|all [rcfile] +photoalbum clean|version|generate|all [rcfile] photoalbum makemake =over @@ -13,10 +13,6 @@ photoalbum makemake Cleans up the working space -=item init - -Initializes the working space - =item version Prints out the version @@ -27,7 +23,7 @@ Generates the static photoalbum =item all -This just runs 'clean init generate' right after another. +This just runs 'clean generate' right after another. =item makemake @@ -41,8 +37,6 @@ Creates a Makefile and photoalbumrc in the current working directory. * See if /etc/default/photoalbum fits your needs. If not, copy /etc/default/photoalbum to ~/.photoalbumrc in order to customize it. -* Run 'photoalbum init' - * Copy all images wanted to the incoming folder (see config file) * Run 'photoalbum generate' diff --git a/share/templates/default/footer.tmpl b/share/templates/default/footer.tmpl index 18e3512..a6b5c78 100644 --- a/share/templates/default/footer.tmpl +++ b/share/templates/default/footer.tmpl @@ -5,7 +5,7 @@ END if [ "${TARBALL_INCLUDE}" = 'yes' ]; then cat <here

+Download all photos in original size here

END fi diff --git a/share/templates/default/header-first-add.tmpl b/share/templates/default/header-first-add.tmpl index f11a346..c6eed3a 100644 --- a/share/templates/default/header-first-add.tmpl +++ b/share/templates/default/header-first-add.tmpl @@ -1,3 +1,3 @@ cat < +

END diff --git a/share/templates/default/header.tmpl b/share/templates/default/header.tmpl index 7d8e5a8..b25143b 100644 --- a/share/templates/default/header.tmpl +++ b/share/templates/default/header.tmpl @@ -1,5 +1,5 @@ -if [ "${IS_SUBALBUM}" = yes ]; then - GOTO_OVERVIEW="

Go to Album overview" +if [ "${is_subalbum}" = yes ]; then + GOTO_OVERVIEW="

Go to Album overview" fi cat < @@ -10,6 +10,7 @@ cat <Album ${ALBUM} (${DESCRIPTION}) - - +

Album ${album} (${description})

+ + END diff --git a/share/templates/default/next.tmpl b/share/templates/default/next.tmpl index 603ed0f..f943bca 100644 --- a/share/templates/default/next.tmpl +++ b/share/templates/default/next.tmpl @@ -1,4 +1,4 @@ cat < -Next $MAXPREVIEWS pictures of current Album +Next ${MAXPREVIEWS} pictures of current Album END diff --git a/share/templates/default/prev.tmpl b/share/templates/default/prev.tmpl index d274bcb..62d5a35 100644 --- a/share/templates/default/prev.tmpl +++ b/share/templates/default/prev.tmpl @@ -1,4 +1,4 @@ cat <Previous $MAXPREVIEWS pictures of current Album +Previous ${MAXPREVIEWS} pictures of current Album

END diff --git a/share/templates/default/preview.tmpl b/share/templates/default/preview.tmpl index 646fc5c..feaa1cf 100644 --- a/share/templates/default/preview.tmpl +++ b/share/templates/default/preview.tmpl @@ -1,5 +1,5 @@ cat < - + + END diff --git a/share/templates/default/redirect.tmpl b/share/templates/default/redirect.tmpl index 8353e7b..aaf95c9 100644 --- a/share/templates/default/redirect.tmpl +++ b/share/templates/default/redirect.tmpl @@ -1,7 +1,7 @@ cat < - + diff --git a/share/templates/default/view.tmpl b/share/templates/default/view.tmpl index 43930de..04962b5 100644 --- a/share/templates/default/view.tmpl +++ b/share/templates/default/view.tmpl @@ -5,10 +5,10 @@ cat <
- +

-Direct link -

$photo

+Direct link +

${photo}

END diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 3e9b61d..9ab9573 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -5,18 +5,8 @@ declare -r VERSION='0.3.1develop' declare -r DEFAULTRC=/etc/default/photoalbum - declare -r ARG1="${1}" ; shift -declare RC="${1}" ; shift - -if [ -z "${RC}" ]; then - RC="${DEFAULTRC}" -fi - -if [ ! -f "${RC}" ]; then - echo "Error: Can not find config file ${RC}" >&2 - exit 1 -fi +declare RC_FILE="${1}" ; shift function usage() { cat - <&2 @@ -25,12 +15,6 @@ function usage() { USAGE } -function init() { - for dir in "${INCOMING_DIR}" "${DIST_DIR}/photos" "${DIST_DIR}/thumbs" "${DIST_DIR}/html"; do - [ -d "${dir}" ] || mkdir -vp "${dir}" - done -} - function clean() { [ -d "${DIST_DIR}" ] && rm -Rf "${DIST_DIR}" } @@ -40,54 +24,50 @@ function tarball() { find "${DIST_DIR}" -maxdepth 1 -type f -name \*.tar -delete if [ "${TARBALL_INCLUDE}" = yes ]; then - local -r BASE=$(basename "${INCOMING_DIR}") + local -r base=$(basename "${INCOMING_DIR}") - echo "Creating tarball ${DIST_DIR}/${TARBALL_NAME} from ${INCOMING_DIR}" + echo "Creating tarball ${DIST_DIR}/${tarball_name} from ${INCOMING_DIR}" cd $(dirname "${INCOMING_DIR}") - tar $TAR_OPTS -f "${DIST_DIR}/${TARBALL_NAME}" "${BASE}" + tar $TAR_OPTS -f "${DIST_DIR}/${tarball_name}" "${base}" cd - &>/dev/null fi } function generate() { if [ ! -d "${INCOMING_DIR}" ]; then - echo "ERROR: You may run init first, no such directory: ${INCOMING_DIR}" >&2 - exit 1 - fi - - if [ ! -d "${DIST_DIR}" ]; then - echo "ERROR: You may run init first, no such directory: ${DIST_DIR}" >&2 + echo "ERROR: You have to create ${INCOMING_DIR} first" >&2 exit 1 fi if [ "${TARBALL_INCLUDE}" = yes ]; then - local -r BASE=$(basename "${INCOMING_DIR}") - local -r NOW=$(date +'%Y-%m-%d-%H%M%S') - # New global variable - TARBALL_NAME="${BASE}-${NOW}${TARBALL_SUFFIX}" + local -r base=$(basename "${INCOMING_DIR}") + local -r now=$(date +'%Y-%m-%d-%H%M%S') + tarball_name="${base}-${now}${TARBALL_SUFFIX}" fi makescale find "${DIST_DIR}" -type f -name \*.html -delete - dirs=( $(find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | sort) ) + local -a dirs=( $(find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | + sort) ) # Figure out wether we want sub-albums or not - if [[ "${SUB_ALBUMS}" != yes || ${#dirs[*]} -eq 0 ]]; then + if [[ "${SUB_albumS}" != yes || ${#dirs[*]} -eq 0 ]]; then makealbumhtml photos html thumbs .. else - IS_SUBALBUM=yes + is_subalbum=yes for dir in ${dirs[*]}; do basename=$(basename "${dir}") - makealbumhtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" ../.. + makealbumhtml \ + "photos/${basename}" "html/${basename}" "thumbs/${basename}" ../.. done # Create an album selection screen - makealbumoverviewhtml <<< ${dirs[*]} + makealbumindexhtml "${dirs[*]}" fi # Create top level index/redirect page - HTML_DIR=./ - REDIRECT_PAGE=./html/index + html_dir=./ + redirect_page=./html/index template redirect index tarball @@ -96,7 +76,7 @@ function generate() { function template() { local -r template=${1} ; shift local -r html=${1} ; shift - local -r dist_html="${DIST_DIR}/${HTML_DIR}" + local -r dist_html="${DIST_DIR}/${html_dir}" #echo "Creating ${dist_html}/${html}.html from ${template}.tmpl" [ ! -d "${dist_html}" ] && mkdir -p "${dist_html}" @@ -122,19 +102,20 @@ function makescale() { function makealbumhtml() { # First initialize some globals (used as template vars) - PHOTOS_DIR="${1}" ; shift - HTML_DIR="${1}" ; shift - THUMBS_DIR="${1}" ; shift - BACKHREF="${1}" ; shift + photos_dir="${1}" ; shift + html_dir="${1}" ; shift + thumbs_dir="${1}" ; shift + backhref="${1}" ; shift local -i num=1 local -i i=0 local name=page-${num} + local next='' template header ${name} template header-first-add ${name} - cd "${DIST_DIR}/${PHOTOS_DIR}" && find ./ -type f | sort | sed 's;^\./;;' | + cd "${DIST_DIR}/${photos_dir}" && find ./ -type f | sort | sed 's;^\./;;' | while read photo; do : $(( i++ )) @@ -160,19 +141,19 @@ function makealbumhtml() { template view ${num}-${i} template footer ${num}-${i} - if [ ! -f "${DIST_DIR}/${THUMBS_DIR}/${photo}" ]; then - echo "Creating thumb ${DIST_DIR}/${THUMBS_DIR}/${photo}"; - dirname=$(dirname "${DIST_DIR}/${THUMBS_DIR}/${photo}") + if [ ! -f "${DIST_DIR}/${thumbs_dir}/${photo}" ]; then + echo "Creating thumb ${DIST_DIR}/${thumbs_dir}/${photo}"; + dirname=$(dirname "${DIST_DIR}/${thumbs_dir}/${photo}") [ ! -d "${dirname}" ] && mkdir -p "${dirname}" convert -geometry x${THUMBGEOMETRY} "${photo}" \ - "${DIST_DIR}/${THUMBS_DIR}/${photo}" + "${DIST_DIR}/${thumbs_dir}/${photo}" fi done - template footer $(cd "${DIST_DIR}/${HTML_DIR}";ls -t page-*.html | - head -n 1 | sed 's/.html//') "${DIST_DIR}/${HTML_DIR}" + template footer $(cd "${DIST_DIR}/${html_dir}";ls -t page-*.html | + head -n 1 | sed 's/.html//') "${DIST_DIR}/${html_dir}" - cd "${DIST_DIR}/${HTML_DIR}" && ls *.html | grep -v page- | cut -d'-' -f1 | uniq | + cd "${DIST_DIR}/${html_dir}" && ls *.html | grep -v page- | cut -d'-' -f1 | uniq | while read prefix; do declare page=$(ls -t ${prefix}-*.html | head -n 1 | sed 's#\(.*\)-.*.html#\1#') @@ -183,45 +164,47 @@ function makealbumhtml() { declare prevredirect=${page}-0 declare nextredirect=${page}-$((lastview+1)) - REDIRECT_PAGE=$(( page-1 ))-${MAXPREVIEWS} + redirect_page=$(( page-1 ))-${MAXPREVIEWS} template redirect ${prevredirect} if [ ${lastview} -eq ${MAXPREVIEWS} ]; then - REDIRECT_PAGE=$(( page+1 ))-1 + redirect_page=$(( page+1 ))-1 else - REDIRECT_PAGE=${page}-${lastview} + redirect_page=${page}-${lastview} template redirect 0-${MAXPREVIEWS} - REDIRECT_PAGE=1-1 + redirect_page=1-1 fi template redirect ${nextredirect} done # Create per album index/redirect page - REDIRECT_PAGE=page-1 + redirect_page=page-1 template redirect index } -function makealbumoverviewhtml() { - HTML_DIR=html - BACKHREF=.. - IS_SUBALBUM=no +function makealbumindexhtml() { + local -a dirs=( "${1}" ) + html_dir=html + backhref=.. + is_subalbum=no template header index template header-first-add index - while read dir; do + for dir in ${dirs[*]}; do basename=$(basename "$dir") - ALBUM=$basename + album=$basename thumbs_dir="${DIST_DIR}/thumbs/${basename}" pictures=$(ls "${thumbs_dir}" | wc -l) - random=$(( 1 + $RANDOM % $pictures )) - RANDOM_THUMB="./thumbs/${basename}"/$(find "$thumbs_dir" -type f -printf "%f\n" | - head -n $random | tail -n 1) + random_num=$(( 1 + $RANDOM % $pictures )) + random_thumb="./thumbs/${basename}"/$(find \ + "$thumbs_dir" -type f -printf "%f\n" | + head -n $random_num | tail -n 1) pages=$(( $pictures / $MAXPREVIEWS + 1)) - test $pages -gt 1 && s=s || s='' - DESCRIPTION="${pictures} pictures / ${pages} page$s" + [ $pages -gt 1 ] && s=s || s='' + description="${pictures} pictures / ${pages} page$s" template index-preview index done @@ -232,44 +215,35 @@ function makemake() { [ ! -f ./photoalbumrc ] && cp /etc/default/photoalbum ./photoalbumrc cat < ./Makefile all: - photoalbum all photoalbumrc + photoalbum generate photoalbumrc clean: photoalbum clean photoalbumrc MAKEFILE echo You may now customize ./photoalbumrc and run make } -if [ -f "${RC}" ]; then - source "${RC}" -else +if [ -z "${RC_FILE}" ]; then if [ -f ~/.photoalbumrc ]; then - source ~/.photoalbumrc + RC_FILE=~/.photoalbumrc + else + RC_FILE="${DEFAULTRC}" fi fi +if [ ! -f "${RC_FILE}" ]; then + echo "Error: Can not find config file ${RC_FILE}" >&2 + exit 1 +fi + +source "${RC_FILE}" + case "${ARG1}" in - all) - init - generate - ;; - init) - init - ;; - clean) - clean - ;; - generate) - generate - ;; - version) - echo "This is Photoalbum Version ${VERSION}" - ;; - makemake) - makemake - ;; - *) - usage - ;; + all) clean; generate;; + clean) clean;; + generate) generate;; + version) echo "This is Photoalbum Version ${VERSION}";; + makemake) makemake;; + *) usage;; esac exit 0 -- cgit v1.2.3 From 61f3efc89247a1cc0d8042db96bf9c4c09f04d26 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Fri, 9 May 2014 10:15:41 +0200 Subject: refactor --- docs/photoalbum.1 | 11 +++-------- docs/photoalbum.txt | 9 ++------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/docs/photoalbum.1 b/docs/photoalbum.1 index 130a5c4..5f47e06 100644 --- a/docs/photoalbum.1 +++ b/docs/photoalbum.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "PHOTOALBUM 1" -.TH PHOTOALBUM 1 "2014-05-07" "photoalbum 0.3.1develop" "User Commands" +.TH PHOTOALBUM 1 "2014-05-09" "photoalbum 0.3.1develop" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -133,14 +133,11 @@ photoalbum \- photoalbum is a minimal bash script for linux to generate static web photo albums. .SH "SYNOPSIS" .IX Header "SYNOPSIS" -photoalbum clean|init|version|generate|all [rcfile] +photoalbum clean|version|generate|all [rcfile] photoalbum makemake .IP "clean" 4 .IX Item "clean" Cleans up the working space -.IP "init" 4 -.IX Item "init" -Initializes the working space .IP "version" 4 .IX Item "version" Prints out the version @@ -149,7 +146,7 @@ Prints out the version Generates the static photoalbum .IP "all" 4 .IX Item "all" -This just runs 'clean init generate' right after another. +This just runs 'clean generate' right after another. .IP "makemake" 4 .IX Item "makemake" Creates a Makefile and photoalbumrc in the current working directory. @@ -159,8 +156,6 @@ Creates a Makefile and photoalbumrc in the current working directory. .IX Subsection "TUTORIAL" * See if /etc/default/photoalbum fits your needs. If not, copy /etc/default/photoalbum to ~/.photoalbumrc in order to customize it. .PP -* Run 'photoalbum init' -.PP * Copy all images wanted to the incoming folder (see config file) .PP * Run 'photoalbum generate' diff --git a/docs/photoalbum.txt b/docs/photoalbum.txt index 32722a7..c2cfb8a 100644 --- a/docs/photoalbum.txt +++ b/docs/photoalbum.txt @@ -3,21 +3,18 @@ NAME static web photo albums. SYNOPSIS - photoalbum clean|init|version|generate|all [rcfile] photoalbum makemake + photoalbum clean|version|generate|all [rcfile] photoalbum makemake clean Cleans up the working space - init - Initializes the working space - version Prints out the version generate Generates the static photoalbum - all This just runs 'clean init generate' right after another. + all This just runs 'clean generate' right after another. makemake Creates a Makefile and photoalbumrc in the current working @@ -28,8 +25,6 @@ SYNOPSIS * See if /etc/default/photoalbum fits your needs. If not, copy /etc/default/photoalbum to ~/.photoalbumrc in order to customize it. - * Run 'photoalbum init' - * Copy all images wanted to the incoming folder (see config file) * Run 'photoalbum generate' -- cgit v1.2.3 From 9ee60634428f24c62b4da45b641975da836585b4 Mon Sep 17 00:00:00 2001 From: "Paul C. Buetow (mars.fritz.box)" Date: Fri, 9 May 2014 10:26:20 +0200 Subject: refactor --- src/photoalbum.sh | 56 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/photoalbum.sh b/src/photoalbum.sh index 9ab9573..c452b93 100755 --- a/src/photoalbum.sh +++ b/src/photoalbum.sh @@ -33,6 +33,16 @@ function tarball() { fi } +function template() { + local -r template=${1} ; shift + local -r html=${1} ; shift + local -r dist_html="${DIST_DIR}/${html_dir}" + + #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" +} + function generate() { if [ ! -d "${INCOMING_DIR}" ]; then echo "ERROR: You have to create ${INCOMING_DIR} first" >&2 @@ -42,22 +52,24 @@ function generate() { if [ "${TARBALL_INCLUDE}" = yes ]; then local -r base=$(basename "${INCOMING_DIR}") local -r now=$(date +'%Y-%m-%d-%H%M%S') - tarball_name="${base}-${now}${TARBALL_SUFFIX}" + declare -r tarball_name="${base}-${now}${TARBALL_SUFFIX}" fi makescale + find "${DIST_DIR}" -type f -name \*.html -delete local -a dirs=( $(find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | sort) ) # Figure out wether we want sub-albums or not - if [[ "${SUB_albumS}" != yes || ${#d