From 290f1524a27408872cb48f885144fb78b03e374e Mon Sep 17 00:00:00 2001
From: Hyperling
Date: Mon, 26 May 2025 13:54:46 -0700
Subject: [PATCH 01/14] Refactor the `photos` page code and begin adding a feed
page named `all`.
---
pages/photos.sh | 326 ++++++++++++++++++++++++++++++------------------
1 file changed, 206 insertions(+), 120 deletions(-)
diff --git a/pages/photos.sh b/pages/photos.sh
index c094b7e..0663846 100755
--- a/pages/photos.sh
+++ b/pages/photos.sh
@@ -2,12 +2,12 @@
# 2024-01-21 Hyperling
# Transition away from PhotoPrism. Helps to save system resources and downsize.
-# Static Variables
+## Static Variables ##
DIR=`dirname $0`
header="\n\t\n\t\tALBUM\n\t\n\t"
footer="\n\t\n"
-# Functions
+## Functions ##
function remove_problem_strings {
file="$1"
sed -i -e 's/#!\/usr\/bin\/php//g' $file
@@ -20,6 +20,7 @@ cd $DIR/..
HELPER_DIR=./pages/helpers
PHOTOS_DIR=./files/photos
mainpage=$PHOTOS_DIR/index.html
+allpage=$PHOTOS_DIR/all/index.html
# Use the cached version if available.
if [[ -e $mainpage ]]; then
@@ -28,146 +29,231 @@ if [[ -e $mainpage ]]; then
exit 0
fi
-# Create the necessary HTML components for a web page.
-$HELPER_DIR/body_open.php > $mainpage
-echo "" >> $mainpage
+## Start the main /photos/ page. ##
+function start_main_page {
+ # Create the necessary HTML components for a web page.
+ $HELPER_DIR/body_open.php > $mainpage
+ echo "" >> $mainpage
-# Give the page a description.
-echo -e "\t\t
" >> $mainpage
-echo -e "\t\t\t
Albums
" >> $mainpage
-echo -e "\t\t
" >> $mainpage
-
-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 $PHOTOS_DIR/ | sort -r | while read album; do
- # Skip files, only read directories.
- if [[ ! -d $PHOTOS_DIR/$album ]]; then
- continue
- fi
-
- # Clean album name.
- album_name=${album}
- album_name=${album_name//_/ }
- album_name=${album_name//-/ }
+ # Give the page a description.
echo -e "\t\t
" >> $mainpage
- # Catch all the upcoming photo records.
- echo -e "\t\t
\n\t\t\t
" >> $mainpage
+ 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
+}
- # Create index page for each photo ALBUM based on its contents.
- page=""
- subpage="$PHOTOS_DIR/$album/index.html"
- $HELPER_DIR/body_open.php > $subpage
+## Close out the main page after the sub pages are done being added. ##
+function end_main_page {
+ # Finish the main /photos/ page.
+ $HELPER_DIR/body_close.php >> $mainpage
+ echo "" >> $mainpage
+ remove_problem_strings $mainpage
+}
- # Add a back button
- echo -en "\n\t\t
" >> $subpage
-
- # Build the ALBUM page.
- echo -e "\t\t
" >> $subpage
- echo -e "\t\t\t
$album_name
" >> $subpage
- echo -e "\t\t
" >> $subpage
-
- ls $PHOTOS_DIR/$album/* | sort | while read photo; do
- # Do not include the index page.
- if [[ $photo == *"index.html" ]]; then
+## Create the album pages. ##
+function build_album_pages {
+ # Display the album names descending.
+ ls $PHOTOS_DIR/ | sort -r | while read album; do
+ # Skip files, only read directories.
+ if [[ ! -d $PHOTOS_DIR/$album ]]; then
continue
fi
- # Clean filename to be a little more presentable.
- # Going with CAPSLOCK. ;)
- typeset -u filename
- filename="`basename $photo`"
- # Remove extension.
- filename="${filename%%.*}"
- # Remove special characters for spaces.
- filename="${filename//_/ }"
- filename="${filename//-/ }"
+ # Clean album name.
+ album_name=${album}
+ album_name=${album_name//_/ }
+ album_name=${album_name//-/ }
+ echo -e "\t\t
" >> $mainpage
- 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`
" >> $mainpage
- else
- # Otherwise put in the PHOTOS page list.
- echo -en "\t\t\t\t
" >> $subpage
+
+ # Build the ALBUM page.
+ echo -e "\t\t
" >> $subpage
+ echo -e "\t\t\t
$album_name
" >> $subpage
+ echo -e "\t\t
" >> $subpage
+
+ ls $PHOTOS_DIR/$album/* | sort | while read photo; do
+ # Do not include the index page.
+ if [[ $photo == *"index.html" ]]; then
+ continue
fi
- echo -e "" >> $mainpage
+
+ # Clean filename to be a little more presentable.
+ # Going with CAPSLOCK. ;)
+ typeset -u filename
+ filename="`basename $photo`"
+ # Remove extension.
+ filename="${filename%%.*}"
+ # Remove special characters for spaces.
+ filename="${filename//_/ }"
+ filename="${filename//-/ }"
+
+ 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`
" >> $mainpage
+ else
+ # Otherwise put in the PHOTOS page list.
+ echo -en "\t\t\t\t
" >> $mainpage
+ fi
+
+ ## Put in the subpage HTML ##
+ # Set the count if this is the first loop.
+ if [[ -z $count ]]; then
+ count=0
+ fi
+ # Add a row for the next 2 images.
+ if (( $count % 2 == 0 )); then
+ echo -e "\t\t
" >> $subpage
+ fi
+ # Add the container for the image and its text.
+ echo -e "\t\t\t
" >> $subpage
+
+ # Close out the ALBUM's page.
+ $HELPER_DIR/body_close.php >> $subpage
+ echo "" >> $subpage
+ remove_problem_strings $subpage
+ done
+}
+
+## Create an ALL page at /photos/all/ ##
+function build_all_page {
+ # - Shows all photos in descending order, as an overall feed.
+ # - Four images wide.
+ # - Has 2 URLs below the image. One to the album, and one to the image.
+ # - Image is a URL to itself as with other pages.
+ # - Images are shown at maximum 500px or so vertical for quick scrolling.
+
+ # Create/overwrite file.
+ $HELPER_DIR/body_open.php > $allpage
+ echo "" >> $allpage
+
+ # Add header.
+ echo -e "\t\t
" >> $allpage
+ echo -e "\t\t\t
All Image Feed
" >> $allpage
+ echo -e "\t\t
" >> $allpage
+
+ # Add images to the page
+ find $PHOTOS_DIR/ ! -name "*".html | sort -r | while read media_file; do
+ media_name="`basename $media_file`"
+ dir_name="`dirname $media_file`"
+
+ media=""
+
+ # Determine how to show the file.
+ if [[ $media_name == *".mp4" ]]; then
+ media=""
+ elif [[ $media_name == *".md" || $media_name == *".txt"]]; then
+ media="
`cat $media_file`
"
fi
- ## Put in the subpage HTML ##
- # Set the count if this is the first loop.
+ # Add a row if count has reset.
if [[ -z $count ]]; then
count=0
fi
- # Add a row for the next 2 images.
- if (( $count % 2 == 0 )); then
- echo -e "\t\t
" >> $subpage
+ if [[ $count == 0 ]]; then
+ echo "
" >> $allpage
fi
- # Add the container for the image and its text.
- echo -e "\t\t\t
" >> $allpage
+
+ # Close the row and reset the the count if full.
+ if [[ $count == 3 ]]; then
+ echo "
" >> $allpage
+ count=0
fi
- # Check if it needs an extra descriptive detail.
- echo -en "\t\t\t\t\t
$filename" >> $subpage
- if [[ $photo == *".mp4" ]]; then
- echo -en " [VIDEO]" >> $subpage
- fi
- # Close the image description and its link.
- echo -e "
\n\t\t\t\t\n\t\t\t
" >> $subpage
- # Close the row after an odd count.
- if (( $count % 2 == 1 )); then
- echo -e "\t\t
" >> $mainpage
+ echo -e "\t\t\t<$a href='/files/photos/all/index.html'" >> $mainpage
+ echo -e "\t\t\t\tclass='col-12 header'>Click Here for the Full Image Feed" >> $mainpage
+ echo -e "\t\t\t" >> $mainpage
+ echo -e "\t\t
" >> $mainpage
}
## Close out the main page after the sub pages are done being added. ##
@@ -63,7 +70,7 @@ function build_album_pages {
# Display the album names descending.
ls $PHOTOS_DIR/ | sort -r | while read album; do
# Skip files, only read directories.
- if [[ ! -d $PHOTOS_DIR/$album ]]; then
+ if [[ ! -d "$PHOTOS_DIR/$album" || "$album" == "all" ]]; then
continue
fi
@@ -73,8 +80,8 @@ function build_album_pages {
album_name=${album_name//-/ }
echo -e "\t\t