Refactor the photos
page code and begin adding a feed page named all
.
This commit is contained in:
parent
fb0ff39013
commit
290f1524a2
100
pages/photos.sh
100
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="<html>\n\t<header>\n\t\t<title>ALBUM</title>\n\t</header>\n\t<body>"
|
||||
footer="\n\t</body>\n</html>"
|
||||
|
||||
# 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,6 +29,8 @@ if [[ -e $mainpage ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
## 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
|
||||
@ -45,7 +48,18 @@ 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.</p>" >> $mainpage
|
||||
echo -e "\t\t\t</div>" >> $mainpage
|
||||
echo -e "\t\t</div>" >> $mainpage
|
||||
}
|
||||
|
||||
## 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 "<!-- Built on `date`. -->" >> $mainpage
|
||||
remove_problem_strings $mainpage
|
||||
}
|
||||
|
||||
## 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.
|
||||
@ -159,15 +173,87 @@ ls $PHOTOS_DIR/ | sort -r | while read album; do
|
||||
# Close out the ALBUM's page.
|
||||
$HELPER_DIR/body_close.php >> $subpage
|
||||
echo "<!-- Built on `date`. -->" >> $subpage
|
||||
|
||||
remove_problem_strings $subpage
|
||||
done
|
||||
}
|
||||
|
||||
# Finish the web page.
|
||||
$HELPER_DIR/body_close.php >> $mainpage
|
||||
echo "<!-- Built on `date`. -->" >> $mainpage
|
||||
## 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.
|
||||
|
||||
remove_problem_strings $mainpage
|
||||
# Create/overwrite file.
|
||||
$HELPER_DIR/body_open.php > $allpage
|
||||
echo "" >> $allpage
|
||||
|
||||
# Add header.
|
||||
echo -e "\t\t<div class='row'>" >> $allpage
|
||||
echo -e "\t\t\t<h1 class='col-12 title'>All Image Feed</h1>" >> $allpage
|
||||
echo -e "\t\t</div>" >> $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="<img src='/$media_file'/ alt="">"
|
||||
|
||||
# Determine how to show the file.
|
||||
if [[ $media_name == *".mp4" ]]; then
|
||||
media="<video width='320px' controls>"
|
||||
media="${media}<source src='/$media_file' type=video/mp4>"
|
||||
media="${media}Your browser does not support videos."
|
||||
media="${media}</video>"
|
||||
elif [[ $media_name == *".md" || $media_name == *".txt"]]; then
|
||||
media="<p>`cat $media_file`</p>"
|
||||
fi
|
||||
|
||||
# Add a row if count has reset.
|
||||
if [[ -z $count ]]; then
|
||||
count=0
|
||||
fi
|
||||
if [[ $count == 0 ]]; then
|
||||
echo "<div class=row text>" >> $allpage
|
||||
fi
|
||||
|
||||
# Add a column.
|
||||
echo "<div class=col-3 center>" >> $allpage
|
||||
|
||||
# Add the image.
|
||||
echo "<a href='$media_file'>$media</a>" >> $allpage
|
||||
|
||||
# Add the URLs.
|
||||
echo "<a href='$dir_name>$dir_name</a>" >> $allpage
|
||||
echo "<a href='$media_file>$media_name</a>" >> $allpage
|
||||
|
||||
# Close the column.
|
||||
echo "</div>" >> $allpage
|
||||
|
||||
# Close the row and reset the the count if full.
|
||||
if [[ $count == 3 ]]; then
|
||||
echo "</div>" >> $allpage
|
||||
count=0
|
||||
fi
|
||||
done
|
||||
|
||||
# Add a final back button.
|
||||
echo -en "\n\t\t<div class='row'>\n\t\t\t<a href='/photos'>" >> $allpage
|
||||
echo -e "<h3 class='col-12 title'>Back</h3></a>\n\t\t</div>" >> $allpage
|
||||
|
||||
# Finish the ALL page.
|
||||
$HELPER_DIR/body_close.php >> $allpage
|
||||
echo "<!-- Built on `date`. -->" >> $allpage
|
||||
remove_problem_strings $allpage
|
||||
}
|
||||
|
||||
## Main ##
|
||||
start_main_page
|
||||
build_album_pages
|
||||
build_all_page
|
||||
end_main_page
|
||||
|
||||
cat $mainpage
|
||||
exit 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user