]> git.sommitrealweird.co.uk Git - bpgallery.git/blobdiff - bpgallery.sh
Add ability to generate pages in a seperate directory
[bpgallery.git] / bpgallery.sh
index ccbb32872da3ea67fb5c7362021b26d61c39b0ad..e532c68573b38e6720fe6b7840d70d7b832341c3 100755 (executable)
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-set -e
 set -f
 
-VERSION="1.1+arch"
+VERSION="1.1.1+arch"
 
 function bpgallery_default_head() {
 cat <<END
@@ -29,7 +28,7 @@ cat <<END
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 <head>
        <title>${TITLE}</title>
-       <link rel="stylesheet" href="style.css" type="text/css" />
+       <link rel="stylesheet" href="${BASEURL}style.css" type="text/css" />
 </head>
 <body>
 END
@@ -134,7 +133,7 @@ function bpgallery_default_page() {
 <h1>${caption}</h1>
 <div class="navigation">
        <ul>
-               <li><a href='${INDEXDOCUMENT}'>Thumbnails</a></li>
+               <li><a href='${BASEURL}${INDEXDOCUMENT}'>Thumbnails</a></li>
 END
        if [[ ! -z $previouspage ]]; then
                $ECHOCOMMAND "<li><a href='${previouspage}'>Previous</a></li>"
@@ -286,6 +285,15 @@ if [[ -z $GENERATEPAGESFORMEDIUMSIZE ]]; then
        GENERATEPAGESFORMEDIUMSIZE=1
 fi
 
+if [[ -z $PAGESDIRECTORY ]]; then
+       PAGESDIRECTORY=""
+else
+       temp=${PAGESDIRECTORY:${#PAGESDIRECTORY}-1:1}
+       if [[ "x$temp" != "x/" ]] && [[ "x$temp" != "x\\" ]]; then
+               PAGESDIRECTORY=${PAGESDIRECTORY}/
+       fi
+fi
+
 if [[ -z $MEDIUMWIDTH ]]; then
        MEDIUMWIDTH=400
 fi
@@ -485,8 +493,12 @@ function generate_pages() {
                else
                        nextpage=${nextimage}.html
                fi
-               filename=${extradir}${currentimage}
-               echo "'$previouspage' '$currentpage' '$nextpage' '$addlink'" >> /tmp/bpgallery-tmp.log
+
+               if [[ "x$PAGESDIRECTORY" != "x" ]]; then
+                       filename=../${extradir}${currentimage}
+               else
+                       filename=${extradir}${currentimage}
+               fi
                if [ "x$currentpage" != "x" ]; then
                        generate_general_page "$previouspage" "$currentpage" "$nextpage" $addlink
                fi
@@ -505,8 +517,12 @@ function generate_pages() {
                else
                        addlink=${currentpage}
                fi
-
-               filename=${extradir}${currentpage}
+               
+               if [[ "x$PAGESDIRECTORY" != "x" ]]; then
+                       filename=../${extradir}${currentpage}
+               else
+                       filename=${extradir}${currentpage}
+               fi
                if [[ $addlinks == 1 ]]; then
                        currentpage=${currentpage}${extra}.html
                        previouspage=${previouspage}${extra}.html
@@ -525,8 +541,6 @@ function generate_medium_pages() {
 
 function generate_general_page() {
 
-       echo 'Generating the page...' >> /tmp/bpgallery-tmp.log
-
        if [[ -z $1 ]]; then
                previouspage=""
        fi
@@ -545,12 +559,13 @@ function generate_general_page() {
        fi
 
        if [ -r captions.txt ]; then
-               caption=$($GREPCOMMAND -E "^${filename}   " captions.txt); caption=${caption#*    }
+               imagefilename=${filename##*/}
+               caption=$($GREPCOMMAND -E "^${imagefilename}    " captions.txt); caption=${caption#*    }
        else
                caption=""
        fi
        
-       $BPGALLERY_PAGE_FUNCTION > "$currentpage"
+       $BPGALLERY_PAGE_FUNCTION > "${PAGESDIRECTORY}$currentpage"
 }
 
 if [[ $OUTPUTHTML != 0 ]]; then
@@ -603,6 +618,19 @@ fi
 
 generate_thumbs
 
+if [[ "x$PAGESDIRECTORY" != "x" ]]; then
+       if [ ! -d $PAGESDIRECTORY ]; then
+               mkdir -p $PAGESDIRECTORY
+       fi
+
+       if [ ! -w $PAGESDIRECTORY ]; then
+               $ECHOCOMMAND "Can't write to $PAGESDIRECTORY directory, exiting"
+               exit 16
+       fi
+
+       BASEURL="../"
+fi
+
 if [ $GENERATEPAGESFORMEDIUMSIZE != 0 ]; then
        generate_medium
        generate_medium_pages
@@ -622,6 +650,7 @@ else
        DESCRIPTION=""
 fi
 
+BASEURL=""
 
 $ECHOCOMMAND "Starting to generate page"
 
@@ -635,7 +664,7 @@ if [ $GENERATEPAGESFORMEDIUMSIZE != 0 ]; then
        extra=__medium
 fi
 
-$FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | $SORTCOMMAND -g | while read filename; do filename=${filename#./}; if [ -r captions.txt ]; then caption=$($GREPCOMMAND -E "^$filename     " captions.txt); caption=${caption#*    }; else caption=""; fi; if [ $GENERATEPAGESFORMEDIUMSIZE != 0 ]; then link=$(bpgallery_escape_url "${filename}${extra}.html"); elif [ $GENERATEPAGESFORFULLSIZE != 0 ]; then link=$(bpgallery_escape_url "${filename}.html"); else link=$(bpgallery_escape_url "$filename"); fi; filename=$(bpgallery_escape_url "$filename"); $BPGALLERY_THUMBSLINE_FUNCTION; done >> ${INDEXDOCUMENT}
+$FINDCOMMAND . $FINDIMAGESOPTIONS | $XARGSCOMMAND -0 -I {} $ECHOCOMMAND {} | $SORTCOMMAND -g | while read filename; do filename=${filename#./}; if [ -r captions.txt ]; then caption=$($GREPCOMMAND -E "^$filename     " captions.txt); caption=${caption#*    }; else caption=""; fi; if [ $GENERATEPAGESFORMEDIUMSIZE != 0 ]; then link=${PAGESDIRECTORY}$(bpgallery_escape_url "${filename}${extra}.html"); elif [ $GENERATEPAGESFORFULLSIZE != 0 ]; then link=${PAGESDIRECTORY}$(bpgallery_escape_url "${filename}.html"); else link=$(bpgallery_escape_url "$filename"); fi; filename=$(bpgallery_escape_url "$filename"); $BPGALLERY_THUMBSLINE_FUNCTION; done >> ${INDEXDOCUMENT}
 
 $BPGALLERY_TAIL_FUNCTION >> ${INDEXDOCUMENT}