summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-02-19 11:01:48 +0000
committerPaul Buetow <paul@buetow.org>2022-02-19 11:01:48 +0000
commit6feae6c65217e8b82c33d3fd4c15be09293ebf9f (patch)
tree666d35cd48ce3598634f536889e5665b5e26c25d /src
parent1c460f748c9695d03d34c37a0abf5f91e7a9c7a2 (diff)
parente2e7f1477f16c97c676501ca9b98907135bb8155 (diff)
merged
Diffstat (limited to 'src')
-rw-r--r--src/photoalbum.default.conf9
-rwxr-xr-xsrc/photoalbum.sh174
2 files changed, 95 insertions, 88 deletions
diff --git a/src/photoalbum.default.conf b/src/photoalbum.default.conf
index 8f4e488..07026f3 100644
--- a/src/photoalbum.default.conf
+++ b/src/photoalbum.default.conf
@@ -1,9 +1,11 @@
# The title of the photoalbum
TITLE='A simple Photoalbum'
-# Diverse default values
-THUMBGEOMETRY=100
-GEOMETRY=1600
+# Thumbnail geometry
+THUMBGEOMETRY=250
+# Normal geometry (when viewing photo). Uncomment, to keep original size.
+GEOMETRY=1200
+# Max previews per page.
MAXPREVIEWS=100
# Diverse directories, need to be full paths, not relative!
@@ -22,4 +24,3 @@ TAR_OPTS='-c'
# Some debugging options
#set -e
#set -x
-
diff --git a/src/photoalbum.sh b/src/photoalbum.sh
index 2295201..74e89b9 100755
--- a/src/photoalbum.sh
+++ b/src/photoalbum.sh
@@ -1,7 +1,7 @@
#!/bin/bash
-# photoalbum (c) 2011 - 2014 by Paul C. Buetow
-# http://photoalbum.buetow.org
+# photoalbum (c) 2011 - 2014, 2022 by Paul Buetow
+# https://codeberg.org/foozone/photoalbum
readonly VERSION='PHOTOALBUMVERSION'
readonly DEFAULTRC=/etc/default/photoalbum
@@ -16,14 +16,14 @@ USAGE
}
makemake () {
- [ ! -f ./photoalbumrc ] && cp /etc/default/photoalbum ./photoalbumrc
+ [ ! -f ./photoalbumrc ] && cp "$DEFAULTRC" ./photoalbumrc
cat <<MAKEFILE > ./Makefile
all:
photoalbum generate photoalbumrc
clean:
photoalbum clean photoalbumrc
MAKEFILE
- echo You may now customize ./photoalbumrc and run make
+ 'echo You may now customize ./photoalbumrc and run make'
}
tarball () {
@@ -32,7 +32,7 @@ tarball () {
readonly base=$(basename "${INCOMING_DIR}")
echo "Creating tarball ${DIST_DIR}/${tarball_name} from ${INCOMING_DIR}"
- cd $(dirname "${INCOMING_DIR}")
+ cd "$(dirname "${INCOMING_DIR}")"
tar $TAR_OPTS -f "${DIST_DIR}/${tarball_name}" "${base}"
cd - &>/dev/null
}
@@ -50,17 +50,21 @@ template() {
scalephotos () {
cd "${INCOMING_DIR}" && find ./ -type f $FIND_ARGS | sort |
while read photo; do
- declare photo=$(sed 's#^\./##' <<< "${photo}")
+ declare photo="$(sed 's#^\./##' <<< "${photo}")"
declare destphoto="${DIST_DIR}/photos/${photo}"
- declare destphoto_nospace=${destphoto// /_}
+ declare destphoto_nospace="${destphoto// /_}"
- declare dirname=$(dirname "${destphoto}")
+ declare dirname="$(dirname "${destphoto}")"
[ ! -d "${dirname}" ] && mkdir -p "${dirname}"
if [ ! -f "${destphoto_nospace}" ]; then
echo "Scaling ${photo} to ${destphoto_nospace}"
- convert -auto-orient \
- -geometry ${GEOMETRY} "${photo}" "${destphoto_nospace}"
+ if [ ! -z "${GEOMETRY}" ]; then
+ convert -auto-orient \
+ -geometry ${GEOMETRY} "${photo}" "${destphoto_nospace}"
+ else
+ convert -auto-orient "${photo}" "${destphoto_nospace}"
+ fi
fi
done
}
@@ -69,15 +73,15 @@ albumhtml () {
declare photos_dir="${1}" ; shift
declare html_dir="${1}" ; shift
declare thumbs_dir="${1}" ; shift
- declare backhref="${1}" ; shift
+ export backhref="${1}" ; shift
declare -i num=1
declare -i i=0
- declare name=page-${num}
+ declare name="page-${num}"
- template header ${name}.html
- template header-first-add ${name}.html
+ template header "${name}.html"
+ template header-first-add "${name}.html"
cd "${DIST_DIR}/${photos_dir}" && find ./ -type f | sort | sed 's;^\./;;' |
while read photo; do
@@ -87,26 +91,26 @@ albumhtml () {
i=1
: $(( num++ ))
- declare next=page-${num}
- template next ${name}.html
- template footer ${name}.html
+ declare next="page-${num}"
+ template next "${name}.html"
+ template footer "${name}.html"
- declare prev=${name}
- declare name=${next}
- template header ${name}.html
- template prev ${name}.html
+ declare prev="${name}"
+ declare name="${next}"
+ template header "${name}.html"
+ template prev "${name}.html"
fi
# Preview page
- template preview ${name}.html
+ template preview "${name}.html"
# View page
- template header ${num}-${i}.html
- template view ${num}-${i}.html
- template footer ${num}-${i}.html
+ template header "${num}-${i}.html"
+ template view "${num}-${i}.html"
+ template footer "${num}-${i}.html"
if [ ! -f "${DIST_DIR}/${thumbs_dir}/${photo}" ]; then
- dirname=$(dirname "${DIST_DIR}/${thumbs_dir}/${photo}")
+ dirname="$(dirname "${DIST_DIR}/${thumbs_dir}/${photo}")"
[ ! -d "${dirname}" ] && mkdir -p "${dirname}"
echo "Creating thumb ${DIST_DIR}/${thumbs_dir}/${photo}";
@@ -116,65 +120,65 @@ albumhtml () {
done
template footer \
- $(cd "${DIST_DIR}/${html_dir}";ls -t page-*.html | head -n 1)
+ "$(cd "${DIST_DIR}/${html_dir}";ls -t page-*.html | head -n 1)"
- 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#')
+ declare page="$(ls -t "${prefix}"-*.html | head -n 1 | sed 's#\(.*\)-.*.html#\1#')"
+ declare lastview="$(ls -t "${prefix}"-*.html | head -n 1 | sed 's/.*-\(.*\).html/\1/')"
- declare lastview=$(ls -t ${prefix}-*.html |
- head -n 1 | sed 's/.*-\(.*\).html/\1/')
+ declare prevredirect="${page}-0"
+ declare nextredirect="${page}-$((lastview+1))"
- declare prevredirect=${page}-0
- declare nextredirect=${page}-$((lastview+1))
+ declare redirect_page="$(( page-1 ))-${MAXPREVIEWS}"
+ template redirect "${prevredirect}.html"
- declare redirect_page=$(( page-1 ))-${MAXPREVIEWS}
- template redirect ${prevredirect}.html
-
- if [ ${lastview} -eq ${MAXPREVIEWS} ]; then
- declare redirect_page=$(( page+1 ))-1
+ if [ "$lastview" -eq "$MAXPREVIEWS" ]; then
+ declare redirect_page="$(( page+1 ))-1"
else
- declare redirect_page=${page}-${lastview}
- template redirect 0-${MAXPREVIEWS}.html
- redirect_page=1-1
+ declare redirect_page="${page}-${lastview}"
+ template redirect "0-${MAXPREVIEWS}.html"
+ redirect_page='1-1'
fi
- template redirect ${nextredirect}.html
+ export redirect_page
+ template redirect "${nextredirect}.html"
done
# Create per album index/redirect page
- declare redirect_page=page-1
- template redirect index.html
+ declare redirect_page='page-1'
+ template 'redirect' 'index.html'
}
albumindexhtml () {
declare -a dirs=( "${1}" )
- declare is_subalbum=no
- declare html_dir=html
- declare backhref=..
+ declare is_subalbum='no'
+ declare html_dir='html'
+ declare backhref='..'
- template header index.html
- template header-first-add index.html
+ template 'header' 'index.html'
+ template 'header-first-add' 'index.html'
for dir in ${dirs[*]}; do
- declare basename=$(basename "$dir")
- declare album=$basename
+ declare basename="$(basename "$dir")"
+ # TODO: All exported vars in UPPERCASE
+ export album="$basename"
declare thumbs_dir="${DIST_DIR}/thumbs/${basename}"
- declare pictures=$(ls "${thumbs_dir}" | wc -l)
- declare random_num=$(( 1 + $RANDOM % $pictures ))
- declare pages=$(( $pictures / $MAXPREVIEWS + 1 ))
+ declare pictures="$(ls "${thumbs_dir}" | wc -l)"
+ declare random_num="$(( 1 + RANDOM % pictures ))"
+ declare pages="$(( pictures / MAXPREVIEWS + 1 ))"
- declare random_thumb="./thumbs/${basename}"/$(find \
+ export random_thumb="./thumbs/${basename}"/$(find \
"${thumbs_dir}" -type f -printf "%f\n" |
head -n ${random_num} | tail -n 1)
- [ ${pages} -gt 1 ] && declare s=s || declare s=''
- declare description="${pictures} pictures / ${pages} page${s}"
- template index-preview index.html
+ declare s=''
+ [ ${pages} -gt 1 ] && s='s'
+ export description="${pictures} pictures / ${pages} page${s}"
+ template 'index-preview' 'index.html'
done
- template footer index.html
+ template 'footer' 'index.html'
}
generate () {
@@ -193,20 +197,18 @@ generate () {
scalephotos
find "${DIST_DIR}" -type f -name \*.html -delete
- declare -a dirs=( $(find "${DIST_DIR}/photos" \
- -mindepth 1 -maxdepth 1 -type d | sort) )
+ declare -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
- declare is_subalbum=no
- albumhtml photos html thumbs ..
+ export is_subalbum='no'
+ albumhtml 'photos' 'html' 'thumbs' '..'
else
- declare is_subalbum=yes
+ export is_subalbum='yes'
for dir in ${dirs[*]}; do
- declare basename=$(basename "${dir}")
- albumhtml \
- "photos/${basename}" "html/${basename}" "thumbs/${basename}" ../..
+ declare basename="$(basename "${dir}")"
+ albumhtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" '../..'
done
# Create an album selection screen
@@ -214,34 +216,38 @@ generate () {
fi
# Create top level index/redirect page
- declare html_dir=./
- declare redirect_page=./html/index
- template redirect index.html
+ declare html_dir='./'
+ declare redirect_page='./html/index'
+ template 'redirect' 'index.html'
- if [ "${TARBALL_INCLUDE}" = yes ]; then
+ if [ "${TARBALL_INCLUDE}" = 'yes' ]; then
tarball
fi
}
recursive () {
- local dir=$(cut -d: -f2 <<< $ARG1)
+ local dir="$(cut -d: -f2 <<< "$ARG1")"
- if [ ! -d $dir ]; then
+ if [ ! -d "$dir" ]; then
echo "Directory $dir does not exist!"
exit 1
fi
- find $dir -type d | grep -v '\.HTML' | while read d; do
- test ! -d $d.HTML && mkdir $d.HTML
- rc_file=$d.HTML/photoalbumrc
- cd $d.HTML && cp $RC_FILE $rc_file && chmod 644 $rc_file
- echo "INCOMING_DIR=$d" >> $rc_file
- echo "DIST_DIR=$d.HTML" >> $rc_file
- echo "ORIGINAL_BASEPATH=../../$(basename $d)" >> $rc_file
- echo 'FIND_ARGS="-maxdepth 1"' >> $rc_file
- photoalbum generate $rc_file
+ find "$dir" -type d | grep -v '\.HTML' | while read -r d; do
+ test ! -d "$d.HTML" && mkdir "$d.HTML "
+ rc_file="$d.HTML/photoalbumrc"
+ cd "$d.HTML" && cp "$RC_FILE" "$rc_file" && chmod 644 "$rc_file"
+
+ {
+ echo "INCOMING_DIR=$d";
+ echo "DIST_DIR=$d.HTML";
+ echo "ORIGINAL_BASEPATH=../../$(basename "$d")";
+ echo 'FIND_ARGS="-maxdepth 1"';
+ } >> "$rc_file"
+
+ photoalbum generate "$rc_file"
cd - &>/dev/null
- test -d $d.HTML && test ! -d $d.HTML/thumbs && rm -Rf $d.HTML
+ test -d "$d.HTML" && test ! -d "$d.HTML/thumbs" && rm -Rf "$d.HTML"
done
}