From cb4dd8ab9ae0cf8c3376a4c139fc0d5134f4010d Mon Sep 17 00:00:00 2001 From: Chad Date: Thu, 25 Jan 2024 03:27:32 +0000 Subject: [PATCH] Cache PHOTOS Page (#11) --- pages/photos.sh | 74 +++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/pages/photos.sh b/pages/photos.sh index 33f6c50..ede75ef 100755 --- a/pages/photos.sh +++ b/pages/photos.sh @@ -3,30 +3,41 @@ # Transition away from PhotoPrism. Helps to save system resources and downsize. # Static Variables +DIR=`dirname $0` header="\n\t
\n\t\tALBUM\n\t
\n\t" footer="\n\t\n" -HELPER_DIR=./pages/helpers -# Move to the main project directory. -cd `dirname $0`/.. +# Move to where this script exists. +cd $DIR + +# Where resources are from the current directory. +HELPER_DIR=../pages/helpers +mainpage=../files/photos/index.html + +# Use the cached version if available. +if [[ -e $mainpage ]]; then + cat $mainpage + echo "" + exit 0 +fi # Create the necessary HTML components for a web page. -$HELPER_DIR/body_open.php -echo "" +$HELPER_DIR/body_open.php > $mainpage +echo "" >> $mainpage # Give the page a description. -echo -e "\t\t
" -echo -e "\t\t\t

Photo Albums

" -echo -e "\t\t
" +echo -e "\t\t
" >> $mainpage +echo -e "\t\t\t

Photo Albums

" >> $mainpage +echo -e "\t\t
" >> $mainpage -echo -e "\t\t
" -echo -e "\t\t\t
" -echo -en "\t\t\t\t

You may click on an album name to " -echo -en "view all of its files, or click on a specific image to bring up the " -echo -en "full resolution. On the album pages you may also click an image or " -echo -e "video name to pull up the full resolution for download.

" -echo -e "\t\t\t
" -echo -e "\t\t
" +echo -e "\t\t
" >> $mainpage +echo -e "\t\t\t
" >> $mainpage +echo -en "\t\t\t\t

You may click on an album name to " >> $mainpage +echo -en "view all of its files, or click on a specific image to bring up the " >> $mainpage +echo -en "full resolution. On the album pages you may also click an image or " >> $mainpage +echo -e "video name to pull up the full resolution for download.

" >> $mainpage +echo -e "\t\t\t
" >> $mainpage +echo -e "\t\t
" >> $mainpage # Display the album names descending. ls files/photos/ | sort -r | while read album; do @@ -39,14 +50,14 @@ ls files/photos/ | sort -r | while read album; do album_name=${album} album_name=${album_name//_/ } album_name=${album_name//-/ } - echo -e "\t\t
" - echo -en "\t\t\t

" - echo -en "$album_name

" - echo -e "\t\t
" + echo -e "\t\t
" >> $mainpage + echo -en "\t\t\t

" >> $mainpage + echo -en "> $mainpage + echo -e "target='_blank' rel='noopener noreferrer'>$album_name

" >> $mainpage + echo -e "\t\t
" >> $mainpage # Catch all the upcoming photo records. - echo -e "\t\t
\n\t\t\t
" + echo -e "\t\t
\n\t\t\t
" >> $mainpage # Create index page for each photo ALBUM based on its contents. page="" @@ -81,15 +92,15 @@ ls files/photos/ | sort -r | while read album; do if [[ $photo == *"/README.md" || $photo == *"/README.txt" ]]; then # If there is a README, show it on the PHOTOS page without a link. - echo -e "\t\t\t\t

`cat $photo`

" + echo -e "\t\t\t\t

`cat $photo`

" >> $mainpage else # Otherwise put in the PHOTOS page list. - echo -en "\t\t\t\t
  • $filename" + echo -en "\t\t\t\t
  • > $mainpage + echo -en "rel='noopener noreferrer'>$filename" >> $mainpage if [[ $photo == *".mp4" ]]; then - echo -en " [VIDEO]" + echo -en " [VIDEO]" >> $mainpage fi - echo -e "
  • " + echo -e "" >> $mainpage fi # Put in the subpage HTML. @@ -117,8 +128,8 @@ ls files/photos/ | sort -r | while read album; do echo -e "\t\t
    " >> $subpage # End album listings on PHOTOS page. - echo -e "\t\t\t
    " - echo -e "\t\t
    " + echo -e "\t\t\t
    " >> $mainpage + echo -e "\t\t" >> $mainpage # Add a final back button echo -en "\n\t\t
    \n\t\t\t" >> $subpage @@ -129,4 +140,7 @@ ls files/photos/ | sort -r | while read album; do done # Finish the web page. -$HELPER_DIR/body_close.php +$HELPER_DIR/body_close.php >> $mainpage + +cat $mainpage +exit 0