2024-01-24 11:02:23 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# 2024-01-21 Hyperling
|
|
|
|
# Transition away from PhotoPrism. Helps to save system resources and downsize.
|
|
|
|
|
|
|
|
# Static Variables
|
2024-01-25 03:27:32 +00:00
|
|
|
DIR=`dirname $0`
|
2024-01-24 11:02:23 +00:00
|
|
|
header="<html>\n\t<header>\n\t\t<title>ALBUM</title>\n\t</header>\n\t<body>"
|
|
|
|
footer="\n\t</body>\n</html>"
|
|
|
|
|
2024-01-25 03:27:32 +00:00
|
|
|
# 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 "<!-- Loaded from cache. :) -->"
|
|
|
|
exit 0
|
|
|
|
fi
|
2024-01-24 11:02:23 +00:00
|
|
|
|
|
|
|
# Create the necessary HTML components for a web page.
|
2024-01-25 03:27:32 +00:00
|
|
|
$HELPER_DIR/body_open.php > $mainpage
|
|
|
|
echo "" >> $mainpage
|
2024-01-24 11:02:23 +00:00
|
|
|
|
|
|
|
# Give the page a description.
|
2024-01-25 03:27:32 +00:00
|
|
|
echo -e "\t\t<div class='row'>" >> $mainpage
|
|
|
|
echo -e "\t\t\t<h1 class='col-12 title'>Photo Albums</h1>" >> $mainpage
|
|
|
|
echo -e "\t\t</div>" >> $mainpage
|
|
|
|
|
|
|
|
echo -e "\t\t<div class='row'>" >> $mainpage
|
|
|
|
echo -e "\t\t\t<div class='col-12 text'>" >> $mainpage
|
|
|
|
echo -en "\t\t\t\t<p>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.</p>" >> $mainpage
|
|
|
|
echo -e "\t\t\t</div>" >> $mainpage
|
|
|
|
echo -e "\t\t</div>" >> $mainpage
|
2024-01-24 11:02:23 +00:00
|
|
|
|
|
|
|
# Display the album names descending.
|
|
|
|
ls files/photos/ | sort -r | while read album; do
|
2024-01-25 02:46:33 +00:00
|
|
|
# Skip files, only read directories.
|
|
|
|
if [[ ! -d files/photos/$album ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2024-01-24 11:02:23 +00:00
|
|
|
# Clean album name.
|
|
|
|
album_name=${album}
|
|
|
|
album_name=${album_name//_/ }
|
|
|
|
album_name=${album_name//-/ }
|
2024-01-25 03:27:32 +00:00
|
|
|
echo -e "\t\t<div class='row'>" >> $mainpage
|
|
|
|
echo -en "\t\t\t<h2 class='col-12 title'>" >> $mainpage
|
|
|
|
echo -en "<a href='/files/photos/$album/index.html' " >> $mainpage
|
|
|
|
echo -e "target='_blank' rel='noopener noreferrer'>$album_name</a></h2>" >> $mainpage
|
|
|
|
echo -e "\t\t</div>" >> $mainpage
|
2024-01-25 02:46:33 +00:00
|
|
|
|
|
|
|
# Catch all the upcoming photo records.
|
2024-01-25 03:27:32 +00:00
|
|
|
echo -e "\t\t<div class='row'>\n\t\t\t<div class='col-12 text'>" >> $mainpage
|
2024-01-24 11:02:23 +00:00
|
|
|
|
2024-01-24 13:57:05 +00:00
|
|
|
# Create index page for each photo ALBUM based on its contents.
|
2024-01-24 11:02:23 +00:00
|
|
|
page=""
|
|
|
|
subpage="files/photos/$album/index.html"
|
|
|
|
$HELPER_DIR/body_open.php > $subpage
|
2024-01-24 13:57:05 +00:00
|
|
|
|
|
|
|
# Add a back button
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -en "\n\t\t<div class='row'>\n\t\t\t<a href='/photos'>" >> $subpage
|
|
|
|
echo -e "<h3 class='col-12 title'>Back</h3></a>\n\t\t</div>" >> $subpage
|
2024-01-24 13:57:05 +00:00
|
|
|
|
|
|
|
# Build the ALBUM page.
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -e "\t\t<div class='row'>" >> $subpage
|
|
|
|
echo -e "\t\t\t<h1 class='col-12 title'>$album_name</h1>" >> $subpage
|
|
|
|
echo -e "\t\t</div>" >> $subpage
|
|
|
|
|
|
|
|
echo -e "\t\t<div class='row text'>" >> $subpage
|
2024-01-24 11:02:23 +00:00
|
|
|
ls files/photos/$album/* | sort | while read photo; do
|
|
|
|
# Do not include the index page.
|
|
|
|
if [[ $photo == *"index.html" ]]; 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//-/ }"
|
|
|
|
|
|
|
|
if [[ $photo == *"/README.md" || $photo == *"/README.txt" ]]; then
|
|
|
|
# If there is a README, show it on the PHOTOS page without a link.
|
2024-01-25 03:27:32 +00:00
|
|
|
echo -e "\t\t\t\t<p>`cat $photo`</p>" >> $mainpage
|
2024-01-24 11:02:23 +00:00
|
|
|
else
|
|
|
|
# Otherwise put in the PHOTOS page list.
|
2024-01-25 03:27:32 +00:00
|
|
|
echo -en "\t\t\t\t<li class='indent'><a href=/$photo target='_blank' " >> $mainpage
|
|
|
|
echo -en "rel='noopener noreferrer'>$filename" >> $mainpage
|
2024-01-24 11:02:23 +00:00
|
|
|
if [[ $photo == *".mp4" ]]; then
|
2024-01-25 03:27:32 +00:00
|
|
|
echo -en " [VIDEO]" >> $mainpage
|
2024-01-24 11:02:23 +00:00
|
|
|
fi
|
2024-01-25 03:27:32 +00:00
|
|
|
echo -e "</a></li>" >> $mainpage
|
2024-01-24 11:02:23 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Put in the subpage HTML.
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -e "\t\t\t<div class='col-6 center'>" >> $subpage
|
|
|
|
echo -en "\t\t\t\t<a href=/$photo target='_blank' " >> $subpage
|
2024-01-24 11:02:23 +00:00
|
|
|
echo -e "rel='noopener noreferrer'>" >> $subpage
|
|
|
|
if [[ $photo == *".mp4" ]]; then
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -e "\t\t\t\t\t<video width='320px' controls>" >> $subpage
|
|
|
|
echo -e "\t\t\t\t\t\t<source src='/$photo' type=video/mp4>" >> $subpage
|
|
|
|
echo -e "\t\t\t\t\t\tYour browser does not support videos." >> $subpage
|
|
|
|
echo -e "\t\t\t\t\t</video>" >> $subpage
|
2024-01-24 11:02:23 +00:00
|
|
|
elif [[ $photo == *".md" || $photo == *".txt" ]]; then
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -e "\t\t\t\t\t<p>`cat $photo`</p>" >> $subpage
|
2024-01-24 11:02:23 +00:00
|
|
|
else
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -e "\t\t\t\t\t<img src='/$photo'/>" >> $subpage
|
2024-01-24 11:02:23 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Add a descriptive link.
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -en "\t\t\t\t\t<p>$filename" >> $subpage
|
2024-01-24 11:02:23 +00:00
|
|
|
if [[ $photo == *".mp4" ]]; then
|
|
|
|
echo -en " [VIDEO]" >> $subpage
|
|
|
|
fi
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -e "</p>\n\t\t\t\t</a>\n\t\t\t</div>" >> $subpage
|
2024-01-24 11:02:23 +00:00
|
|
|
done
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -e "\t\t</div>" >> $subpage
|
2024-01-24 11:02:23 +00:00
|
|
|
|
2024-01-25 02:46:33 +00:00
|
|
|
# End album listings on PHOTOS page.
|
2024-01-25 03:27:32 +00:00
|
|
|
echo -e "\t\t\t</div>" >> $mainpage
|
|
|
|
echo -e "\t\t</div>" >> $mainpage
|
2024-01-24 11:02:23 +00:00
|
|
|
|
2024-01-24 13:57:05 +00:00
|
|
|
# Add a final back button
|
2024-01-25 02:46:33 +00:00
|
|
|
echo -en "\n\t\t<div class='row'>\n\t\t\t<a href='/photos'>" >> $subpage
|
|
|
|
echo -e "<h3 class='col-12 title'>Back</h3></a>\n\t\t</div>" >> $subpage
|
2024-01-24 13:57:05 +00:00
|
|
|
|
2024-01-24 11:02:23 +00:00
|
|
|
# Close out the ALBUM's page.
|
|
|
|
$HELPER_DIR/body_close.php >> $subpage
|
|
|
|
done
|
|
|
|
|
|
|
|
# Finish the web page.
|
2024-01-25 03:27:32 +00:00
|
|
|
$HELPER_DIR/body_close.php >> $mainpage
|
|
|
|
|
|
|
|
cat $mainpage
|
|
|
|
exit 0
|