summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-02-19 23:02:51 +0000
committerPaul Buetow <paul@buetow.org>2022-02-20 10:18:39 +0000
commit38abc2ecb3cbc70aeb11d9d390d9a6ef53478a23 (patch)
tree47b93bf8e569886f123dcf6b8d62167f7f31b0f1
parent6feae6c65217e8b82c33d3fd4c15be09293ebf9f (diff)
ShellCheck OK now. Also, some refactorings.
-rw-r--r--IDEA.md1
-rw-r--r--Makefile23
-rw-r--r--README.pod58
-rw-r--r--docs/photoalbum.1184
-rw-r--r--docs/photoalbum.pod58
-rw-r--r--docs/photoalbum.txt45
-rw-r--r--share/templates/default/next.tmpl6
-rw-r--r--share/templates/default/prev.tmpl4
-rwxr-xr-xsrc/photoalbum.sh429
9 files changed, 237 insertions, 571 deletions
diff --git a/IDEA.md b/IDEA.md
deleted file mode 100644
index aa32565..0000000
--- a/IDEA.md
+++ /dev/null
@@ -1 +0,0 @@
-I could use https://masonry.desandro.com/ to line up the photos niceley. But also keep a HTML-only version available.
diff --git a/Makefile b/Makefile
index 8c10c7f..7bbb0ca 100644
--- a/Makefile
+++ b/Makefile
@@ -21,17 +21,22 @@ deinstall:
clean:
test -d ./bin && rm -Rf ./bin || exit 0
test -d ./debian/photoalbum && rm -Rf ./debian/photoalbum || exit 0
-# Builds the documentation into a manpage
shellcheck:
# SC1090: ShellCheck can't follow non-constant source. Use a directive to specify location.
- # SC2012: Use find instead of ls to better handle non-alphanumeric filenames.
- # SC2155: Declare and assign separately to avoid masking return values.
- # SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
- # SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting).
+ # SC2001: See if you can use ${variable//search/replace} instead.
+ # SC2010: Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
+ # SC2012: Use find instead of ls to better handle non-alphanumeric filenames.
+ # SC2103: Use a ( subshell ) to avoid having to cd back.
+ # SC2155: Declare and assign separately to avoid masking return values.
+ # SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
+ # SC2207: Prefer mapfile or read -a to split command output (or quote to avoid splitting).
shellcheck \
--exclude SC1090 \
- --exclude SC2012 \
- --exclude SC2155 \
- --exclude SC2164 \
- --exclude SC2207 \
+ --exclude SC2001 \
+ --exclude SC2010 \
+ --exclude SC2012 \
+ --exclude SC2103 \
+ --exclude SC2155 \
+ --exclude SC2164 \
+ --exclude SC2207 \
./src/photoalbum.sh
diff --git a/README.pod b/README.pod
deleted file mode 100644
index 9c55dd7..0000000
--- a/README.pod
+++ /dev/null
@@ -1,58 +0,0 @@
-=head1 NAME
-
-photoalbum - photoalbum is a minimal bash script for linux to generate static web photo albums.
-
-=head1 SYNOPSIS
-
-photoalbum clean|generate|version|recursive:DIR [rcfile]
-photoalbum makemake
-
-=over
-
-=item clean
-
-Cleans up the working space
-
-=item version
-
-Prints out the version
-
-=item generate
-
-Generates the static photoalbum
-
-=item makemake
-
-Creates a Makefile and photoalbumrc in the current working directory.
-
-=back
-
-=head2 RCFILE
-
-=head2 TUTORIAL
-
-* See if /etc/default/photoalbum fits your needs. If not, copy /etc/default/photoalbum to ~/.photoalbumrc in order to customize it.
-
-* Copy all images wanted to the incoming folder (see config file)
-
-* Run 'photoalbum generate'
-
-* Distribute the ./dist directory
-
-* Clean the mess up with 'photoalbum clean'
-
-It is possible to specify a custom rcfile path too.
-
-=head3 HTML TEMPLATES
-
-Go to the templates directory and edit them as wished.
-
-=head1 LICENSE
-
-See package description or project website.
-
-=head1 AUTHOR
-
-Paul Buetow - <http://buetow.org>
-
-=cut
diff --git a/docs/photoalbum.1 b/docs/photoalbum.1
deleted file mode 100644
index 146d2d4..0000000
--- a/docs/photoalbum.1
+++ /dev/null
@@ -1,184 +0,0 @@
-.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)
-.\"
-.\" Standard preamble:
-.\" ========================================================================
-.de Sp \" Vertical space (when we can't use .PP)
-.if t .sp .5v
-.if n .sp
-..
-.de Vb \" Begin verbatim text
-.ft CW
-.nf
-.ne \\$1
-..
-.de Ve \" End verbatim text
-.ft R
-.fi
-..
-.\" Set up some character translations and predefined strings. \*(-- will
-.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
-.\" double quote, and \*(R" will give a right double quote. \*(C+ will
-.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
-.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
-.\" nothing in troff, for use with C<>.
-.tr \(*W-
-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
-.ie n \{\
-. ds -- \(*W-
-. ds PI pi
-. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
-. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
-. ds L" ""
-. ds R" ""
-. ds C` ""
-. ds C' ""
-'br\}
-.el\{\
-. ds -- \|\(em\|
-. ds PI \(*p
-. ds L" ``
-. ds R" ''
-. ds C`
-. ds C'
-'br\}
-.\"
-.\" Escape single quotes in literal strings from groff's Unicode transform.
-.ie \n(.g .ds Aq \(aq
-.el .ds Aq '
-.\"
-.\" If the F register is >0, we'll generate index entries on stderr for
-.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
-.\" entries marked with X<> in POD. Of course, you'll have to process the
-.\" output yourself in some meaningful fashion.
-.\"
-.\" Avoid warning from groff about undefined register 'F'.
-.de IX
-..
-.nr rF 0
-.if \n(.g .if rF .nr rF 1
-.if (\n(rF:(\n(.g==0)) \{\
-. if \nF \{\
-. de IX
-. tm Index:\\$1\t\\n%\t"\\$2"
-..
-. if !\nF==2 \{\
-. nr % 0
-. nr F 2
-. \}
-. \}
-.\}
-.rr rF
-.\"
-.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
-.\" Fear. Run. Save yourself. No user-serviceable parts.
-. \" fudge factors for nroff and troff
-.if n \{\
-. ds #H 0
-. ds #V .8m
-. ds #F .3m
-. ds #[ \f1
-. ds #] \fP
-.\}
-.if t \{\
-. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
-. ds #V .6m
-. ds #F 0
-. ds #[ \&
-. ds #] \&
-.\}
-. \" simple accents for nroff and troff
-.if n \{\
-. ds ' \&
-. ds ` \&
-. ds ^ \&
-. ds , \&
-. ds ~ ~
-. ds /
-.\}
-.if t \{\
-. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
-. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
-. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
-. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
-. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
-. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
-.\}
-. \" troff and (daisy-wheel) nroff accents
-.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
-.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
-.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
-.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
-.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
-.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
-.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
-.ds ae a\h'-(\w'a'u*4/10)'e
-.ds Ae A\h'-(\w'A'u*4/10)'E
-. \" corrections for vroff
-.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
-.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
-. \" for low resolution devices (crt and lpr)
-.if \n(.H>23 .if \n(.V>19 \
-\{\
-. ds : e
-. ds 8 ss
-. ds o a
-. ds d- d\h'-1'\(ga
-. ds D- D\h'-1'\(hy
-. ds th \o'bp'
-. ds Th \o'LP'
-. ds ae ae
-. ds Ae AE
-.\}
-.rm #[ #] #H #V #F C
-.\" ========================================================================
-.\"
-.IX Title "PHOTOALBUM 1"
-.TH PHOTOALBUM 1 "2022-02-05" "photoalbum 0.4.5" "User Commands"
-.\" For nroff, turn off justification. Always turn off hyphenation; it makes
-.\" way too many mistakes in technical documents.
-.if n .ad l
-.nh
-.SH "NAME"
-photoalbum \- photoalbum is a minimal bash script for linux to generate static web photo albums.
-.SH "SYNOPSIS"
-.IX Header "SYNOPSIS"
-photoalbum clean|generate|version|recursive:DIR [rcfile]
-photoalbum makemake
-.IP "clean" 4
-.IX Item "clean"
-Cleans up the working space
-.IP "version" 4
-.IX Item "version"
-Prints out the version
-.IP "generate" 4
-.IX Item "generate"
-Generates the static photoalbum
-.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"
-.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
-* Copy all images wanted to the incoming folder (see config file)
-.PP
-* Run 'photoalbum generate'
-.PP
-* Distribute the ./dist directory
-.PP
-* Clean the mess up with 'photoalbum clean'
-.PP
-It is possible to specify a custom rcfile path too.
-.PP
-\fI\s-1HTML TEMPLATES\s0\fR
-.IX Subsection "HTML TEMPLATES"
-.PP
-Go to the templates directory and edit them as wished.
-.SH "LICENSE"
-.IX Header "LICENSE"
-See package description or project website.
-.SH "AUTHOR"
-.IX Header "AUTHOR"
-Paul Buetow \- <http://buetow.org>
diff --git a/docs/photoalbum.pod b/docs/photoalbum.pod
deleted file mode 100644
index 9c55dd7..0000000
--- a/docs/photoalbum.pod
+++ /dev/null
@@ -1,58 +0,0 @@
-=head1 NAME
-
-photoalbum - photoalbum is a minimal bash script for linux to generate static web photo albums.
-
-=head1 SYNOPSIS
-
-photoalbum clean|generate|version|recursive:DIR [rcfile]
-photoalbum makemake
-
-=over
-
-=item clean
-
-Cleans up the working space
-
-=item version
-
-Prints out the version
-
-=item generate
-
-Generates the static photoalbum
-
-=item makemake
-
-Creates a Makefile and photoalbumrc in the current working directory.
-
-=back
-
-=head2 RCFILE
-
-=head2 TUTORIAL
-
-* See if /etc/default/photoalbum fits your needs. If not, copy /etc/default/photoalbum to ~/.photoalbumrc in order to customize it.
-
-* Copy all images wanted to the incoming folder (see config file)
-
-* Run 'photoalbum generate'
-
-* Distribute the ./dist directory
-
-* Clean the mess up with 'photoalbum clean'
-
-It is possible to specify a custom rcfile path too.
-
-=head3 HTML TEMPLATES
-
-Go to the templates directory and edit them as wished.
-
-=head1 LICENSE
-
-See package description or project website.
-
-=head1 AUTHOR
-
-Paul Buetow - <http://buetow.org>
-
-=cut
diff --git a/docs/photoalbum.txt b/docs/photoalbum.txt
deleted file mode 100644
index 56d7806..0000000
--- a/docs/photoalbum.txt
+++ /dev/null
@@ -1,45 +0,0 @@
-NAME
- photoalbum - photoalbum is a minimal bash script for linux to generate
- static web photo albums.
-
-SYNOPSIS
- photoalbum clean|generate|version|recursive:DIR [rcfile] photoalbum
- makemake
-
- clean
- Cleans up the working space
-
- version
- Prints out the version
-
- generate
- Generates the static photoalbum
-
- makemake
- Creates a Makefile and photoalbumrc in the current working
- directory.
-
- RCFILE
- TUTORIAL
- * See if /etc/default/photoalbum fits your needs. If not, copy
- /etc/default/photoalbum to ~/.photoalbumrc in order to customize it.
-
- * Copy all images wanted to the incoming folder (see config file)
-
- * Run 'photoalbum generate'
-
- * Distribute the ./dist directory
-
- * Clean the mess up with 'photoalbum clean'
-
- It is possible to specify a custom rcfile path too.
-
- HTML TEMPLATES
- Go to the templates directory and edit them as wished.
-
-LICENSE
- See package description or project website.
-
-AUTHOR
- Paul Buetow - <http://buetow.org>
-
diff --git a/share/templates/default/next.tmpl b/share/templates/default/next.tmpl
index f943bca..e36d185 100644
--- a/share/templates/default/next.tmpl
+++ b/share/templates/default/next.tmpl
@@ -1,4 +1,6 @@
cat <<END
-<br />
-<a href='${next}.html'>Next ${MAXPREVIEWS} pictures of current Album</a>
+</p>
+<div>
+ <a href='${next}.html'>Next ${MAXPREVIEWS} pictures of current Album</a>
+</div>
END
diff --git a/share/templates/default/prev.tmpl b/share/templates/default/prev.tmpl
index 770cf68..528806a 100644
--- a/share/templates/default/prev.tmpl
+++ b/share/templates/default/prev.tmpl
@@ -1,4 +1,6 @@
cat <<END
-<a href='${prev}.html'>Previous ${MAXPREVIEWS} pictures of current Album</a>
+<div>
+ <a href='${prev}.html'>Previous ${MAXPREVIEWS} pictures of current Album</a>
+</div>
<p align='center'>
END
diff --git a/src/photoalbum.sh b/src/photoalbum.sh
index 74e89b9..242e756 100755
--- a/src/photoalbum.sh
+++ b/src/photoalbum.sh
@@ -1,278 +1,281 @@
-#!/bin/bash
+#!/bin/env bash
# photoalbum (c) 2011 - 2014, 2022 by Paul Buetow
# https://codeberg.org/foozone/photoalbum
readonly VERSION='PHOTOALBUMVERSION'
-readonly DEFAULTRC=/etc/default/photoalbum
-readonly ARG1="${1}" ; shift
-declare RC_FILE="${1}" ; shift
+readonly DEFAULTRC='/etc/default/photoalbum'
+declare ARG1="$1" ; shift
+declare RC_FILE="$1" ; shift
usage () {
- cat - <<USAGE >&2
- Usage:
- $0 clean|generate|version|makemake|recursive:DIR [rcfile]
+ cat - <<USAGE >&2
+ Usage:
+ $0 clean|generate|version|makemake|recursive:DIR [rcfile]
USAGE
}
makemake () {
- [ ! -f ./photoalbumrc ] && cp "$DEFAULTRC" ./photoalbumrc
- cat <<MAKEFILE > ./Makefile
+ [ ! -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 () {
- # Cleanup tarball from prev run if any
- find "${DIST_DIR}" -maxdepth 1 -type f -name \*.tar -delete
- readonly base=$(basename "${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}"
- cd - &>/dev/null
+ # Cleanup tarball from prev run if any
+ find "$DIST_DIR" -maxdepth 1 -type f -name \*.tar -delete
+ declare base="$(basename "$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"
+ cd - &>/dev/null
}
-template() {
- readonly template=${1} ; shift
- readonly html=${1} ; shift
- readonly dist_html="${DIST_DIR}/${html_dir}"
+template () {
+ declare template="$1" ; shift
+ declare html="$1" ; shift
+ declare dist_html="$DIST_DIR/$html_dir"
+ echo "Generating $dist_html/$html"
- # Creating ${dist_html}/${html}.html from ${template}.tmpl
- [ ! -d "${dist_html}" ] && mkdir -p "${dist_html}"
- source "${TEMPLATE_DIR}/${template}.tmpl" >> "${dist_html}/${html}"
+ [ ! -d "$dist_html" ] && mkdir -p "$dist_html"
+ source "$TEMPLATE_DIR/$template.tmpl" >> "$dist_html/$html"
}
scalephotos () {
- cd "${INCOMING_DIR}" && find ./ -type f $FIND_ARGS | sort |
- while read photo; do
- declare photo="$(sed 's#^\./##' <<< "${photo}")"
- declare destphoto="${DIST_DIR}/photos/${photo}"
- declare destphoto_nospace="${destphoto// /_}"
-
- declare dirname="$(dirname "${destphoto}")"
- [ ! -d "${dirname}" ] && mkdir -p "${dirname}"
-
- if [ ! -f "${destphoto_nospace}" ]; then
- echo "Scaling ${photo} to ${destphoto_nospace}"
- if [ ! -z "${GEOMETRY}" ]; then
- convert -auto-orient \
- -geometry ${GEOMETRY} "${photo}" "${destphoto_nospace}"
- else
- convert -auto-orient "${photo}" "${destphoto_nospace}"
- fi
- fi
- done
+ cd "$INCOMING_DIR" && find ./ -maxdepth 1 -type f | sort |
+ while read -r photo; do
+ declare photo="$(sed 's#^\./##' <<< "$photo")"
+ declare destphoto="$DIST_DIR/photos/$photo"
+ declare destphoto_nospace="${destphoto// /_}"
+ declare dirname="$(dirname "$destphoto")"
+ [ ! -d "$dirname" ] && mkdir -p "$dirname"
+
+ if [ -f "$destphoto_nospace" ]; then
+ echo "Already exists: $destphoto_nospace"
+ continue
+ fi
+
+ echo "Scaling $photo to $destphoto_nospace"
+ if [ -n "$GEOMETRY" ]; then
+ convert -auto-orient -geometry "$GEOMETRY" "$photo" "$destphoto_nospace"
+ else
+ convert -auto-orient "$photo" "$destphoto_nospace"
+ fi
+ done
}
albumhtml () {
- declare photos_dir="${1}" ; shift
- declare html_dir="${1}" ; shift
- declare thumbs_dir="${1}" ; shift
- export backhref="${1}" ; shift
-
- declare -i num=1
- declare -i i=0
-
- declare name="page-${num}"
-
- 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
- : $(( i++ ))
-
- if [ ${i} -gt ${MAXPREVIEWS} ]; then
- i=1
- : $(( num++ ))
-
- 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"
- fi
+ declare photos_dir="$1" ; shift
+ declare html_dir="$1" ; shift
+ declare thumbs_dir="$1" ; shift
+ export backhref="$1" ; shift
+
+ declare -i num=1
+ declare -i i=0
+
+ declare name="page-$num"
+
+ template header "$name.html"
+ template header-first-add "$name.html"
+
+ cd "$DIST_DIR/$photos_dir" && find ./ -type f | sort | sed 's;^\./;;' |
+ while read -r photo; do
+ : $(( i++ ))
+
+ if [ "$i" -gt "$MAXPREVIEWS" ]; then
+ i=1
+ : $(( num++ ))
+
+ declare next="page-$num"
+ template next "$name.html"
+ template footer "$name.html"
+
+ export prev="$name"
+ declare name="$next"
+ template header "$name.html"
+ template prev "$name.html"
+ fi
+
+ # Preview page
+ template preview "$name.html"
+ # View page
+ template header "$num-$i.html"
+ template view "$num-$i.html"
+ template footer "$num-$i.html"
+
+ if [ -f "$DIST_DIR/$thumbs_dir/$photo" ]; then
+ echo "Already exists: $DIST_DIR/$thumbs_dir/$photo"
+ continue
+ fi
+
+ dirname="$(dirname "$DIST_DIR/$thumbs_dir/$photo")"
+ test ! -d "$dirname" && mkdir -p "$dirname"
+
+ echo "Creating thumb $DIST_DIR/$thumbs_dir/$photo"
+ convert -geometry "x$THUMBGEOMETRY" "$photo" "$DIST_DIR/$thumbs_dir/$photo"
+ done
- # Preview page
- template preview "${name}.html"
+ template footer "$(cd "$DIST_DIR/$html_dir";ls -t page-*.html | head -n 1)"
- # View page
- template header "${num}-${i}.html"
- template view "${num}-${i}.html"
- template footer "${num}-${i}.html"
+ cd "$DIST_DIR/$html_dir" && ls | grep '.*\.html$' |
+ grep -v page- | cut -d'-' -f1 | uniq |
- if [ ! -f "${DIST_DIR}/${thumbs_dir}/${photo}" ]; then
- dirname="$(dirname "${DIST_DIR}/${thumbs_dir}/${photo}")"
- [ ! -d "${dirname}" ] && mkdir -p "${dirname}"
+ while read -r prefix; do
+ 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/')"
- echo "Creating thumb ${DIST_DIR}/${thumbs_dir}/${photo}";
- convert -geometry x${THUMBGEOMETRY} "${photo}" \
- "${DIST_DIR}/${thumbs_dir}/${photo}"
- fi
- done
+ declare prevredirect="${page}-0"
+ declare nextredirect="${page}-$((lastview+1))"
- template footer \
- "$(cd "${DIST_DIR}/${html_dir}";ls -t page-*.html | head -n 1)"
+ declare redirect_page="$(( page-1 ))-${MAXPREVIEWS}"
+ template redirect "$prevredirect.html"
- 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 lastview="$(ls -t "${prefix}"-*.html | head -n 1 | sed 's/.*-\(.*\).html/\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'
+ fi
- declare prevredirect="${page}-0"
- declare nextredirect="${page}-$((lastview+1))"
+ export redirect_page
+ template redirect "$nextredirect.html"
+ done
- declare redirect_page="$(( page-1 ))-${MAXPREVIEWS}"
- template redirect "${prevredirect}.html"
+ # Create per album index/redirect page
+ declare redirect_page='page-1'
+ template 'redirect' 'index.html'
+}
- if [ "$lastview" -eq "$MAXPREVIEWS" ]; then
- declare redirect_page="$(( page+1 ))-1"
+albumindexhtml () {
+ declare -a dirs=( "$1" )
+ declare is_subalbum='no'
+ declare html_dir='html'
+ declare backhref='..'
- else
- declare redirect_page="${page}-${lastview}"
- template redirect "0-${MAXPREVIEWS}.html"
- redirect_page='1-1'
- fi
- export redirect_page
- template redirect "${nextredirect}.html"
- done
+ template 'header' 'index.html'
+ template 'header-first-add' 'index.html'
- # Create per album index/redirect page
- declare redirect_page='page-1'
- template 'redirect' 'index.html'
-}
+ for dir in ${dirs[*]}; do
+ declare basename="$(basename "$dir")"
+ 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 ))"
+
+ export random_thumb="./thumbs/$basename"/$(find \
+ "$thumbs_dir" -type f -printf "%f\n" |
+ head -n $random_num | tail -n 1)
+
+ declare s=''
+ [ $pages -gt 1 ] && s='s'
+ export description="$pictures pictures / $pages page$s"
+ template 'index-preview' 'index.html'
+ done
-albumindexhtml () {
- declare -a dirs=( "${1}" )
- declare is_subalbum='no'
- declare html_dir='html'
- declare backhref='..'
-
- template 'header' 'index.html'
- template 'header-first-add' 'index.html'
-
- for dir in ${dirs[*]}; do
- 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 ))"
-
- export random_thumb="./thumbs/${basename}"/$(find \
- "${thumbs_dir}" -type f -printf "%f\n" |
- head -n ${random_num} | tail -n 1)
-
- 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 () {
- if [ ! -d "${INCOMING_DIR}" ]; then
- echo "ERROR: You have to create ${INCOMING_DIR} first" >&2
- exit 1
- fi
-
- if [ "${TARBALL_INCLUDE}" = yes ]; then
- readonly base=$(basename "${INCOMING_DIR}")
- readonly now=$(date +'%Y-%m-%d-%H%M%S')
- readonly tarball_name="${base}-${now}${TARBALL_SUFFIX}"
- fi
+ if [ ! -d "$INCOMING_DIR" ]; then
+ echo "ERROR: You have to create $INCOMING_DIR first" >&2
+ exit 1
+ fi
- test ! -d "${DIST_DIR}/photos" && mkdir -p "${DIST_DIR}/photos"
- scalephotos
+ if [ "$TARBALL_INCLUDE" = yes ]; then
+ declare base="$(basename "$INCOMING_DIR")"
+ declare now="$(date +'%Y-%m-%d-%H%M%S')"
+ declare tarball_name="${base}-${now}$TARBALL_SUFFIX"
+ fi
- find "${DIST_DIR}" -type f -name \*.html -delete
- declare -a dirs=( $(find "${DIST_DIR}/photos" -mindepth 1 -maxdepth 1 -type d | sort) )
+ test ! -d "$DIST_DIR/photos" && mkdir -p "$DIST_DIR/photos"
+ scalephotos
- # Figure out wether we want sub-albums or not
- if [[ "${SUB_ALBUMS}" != yes || ${#dirs[*]} -eq 0 ]]; then
- export is_subalbum='no'
- albumhtml 'photos' 'html' 'thumbs' '..'
+ find "$DIST_DIR" -type f -name \*.html -delete
+ declare -a dirs=( $(find "$DIST_DIR/photos" -mindepth 1 -maxdepth 1 -type d | sort) )
- else
- export is_subalbum='yes'
- for dir in ${dirs[*]}; do
- declare basename="$(basename "${dir}")"
- albumhtml "photos/${basename}" "html/${basename}" "thumbs/${basename}" '../..'
- done
+ # Figure out wether we want sub-albums or not
+ if [[ "$SUB_ALBUMS" != yes || ${#dirs[*]} -eq 0 ]]; then
+ export is_subalbum='no'
+ albumhtml 'photos' 'html' 'thumbs' '..'
- # Create an album selection screen
- albumindexhtml "${dirs[*]}"
- fi
+ else
+ export is_subalbum='yes'
+ for dir in ${dirs[*]}; do
+ declare basename="$(basename "$dir")"
+ albumhtml "photos/$basename" "html/$basename" "thumbs/$basename" '../..'
+ done
+
+ # Create an album selection screen
+ albumindexhtml "${dirs[*]}"
+ fi
- # Create top level index/redirect page
- declare html_dir='./'
- declare redirect_page='./html/index'
- template 'redirect' 'index.html'
+ # Create top level index/redirect page
+ declare html_dir='./'
+ declare redirect_page='./html/index'
+ template 'redirect' 'index.html'
- if [ "${TARBALL_INCLUDE}" = 'yes' ]; then
- tarball
- fi
+ if [ "$TARBALL_INCLUDE" = 'yes' ]; then
+ tarball
+ fi
}
recursive () {
- local dir="$(cut -d: -f2 <<< "$ARG1")"
-
- if [ ! -d "$dir" ]; then
- echo "Directory $dir does not exist!"
- exit 1
- fi
+ local dir="$(cut -d: -f2 <<< "$ARG1")"
- 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"
+ if [ ! -d "$dir" ]; then
+ echo "Directory $dir does not exist!"
+ exit 1
+ fi
- photoalbum generate "$rc_file"
- cd - &>/dev/null
- test -d "$d.HTML" && test ! -d "$d.HTML/thumbs" && rm -Rf "$d.HTML"
- done
+ 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")";
+ } >> "$rc_file"
+
+ photoalbum generate "$rc_file"
+ cd - &>/dev/null
+ test -d "$d.HTML" && test ! -d "$d.HTML/thumbs" && rm -Rf "$d.HTML"
+ done
}
-if [ -z "${RC_FILE}" ]; then
- if [ -f ~/.photoalbumrc ]; then
- RC_FILE=~/.photoalbumrc
- else
- RC_FILE="${DEFAULTRC}"
- fi
+if [ -z "$RC_FILE" ]; then
+ if [ -f photoalbumrc ]; then
+ RC_FILE=photoalbumrc
+ elif [ -f ~/.photoalbumrc ]; then
+ 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
+if [ ! -f "$RC_FILE" ]; then
+ echo "Error: Can not find config file $RC_FILE" >&2
+ exit 1
fi
-source "${RC_FILE}"
+source "$RC_FILE"
-case "${ARG1}" in
- clean) [ -d "${DIST_DIR}" ] && rm -Rf "${DIST_DIR}";;
- generate) generate;;
- version) echo "This is Photoalbum Version ${VERSION}";;
- makemake) makemake;;
- recursive*) recursive;;
- *) usage;;
+case "$ARG1" in
+ clean) [ -d "$DIST_DIR" ] && rm -Rf "$DIST_DIR";;
+ generate) generate;;
+ version) echo "This is Photoalbum Version $VERSION";;
+ makemake) makemake;;
+ recursive*) recursive;;
+ *) usage;;
esac
exit 0