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 - echo -en "\t\t\t

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

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

Albums

" >> $mainpage 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 + echo -en "\t\t\t

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

" >> $mainpage + 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
  • > $mainpage - echo -en "rel='noopener noreferrer'>$filename" >> $mainpage - if [[ $photo == *".mp4" ]]; then - echo -en " [VIDEO]" >> $mainpage + # Catch all the upcoming photo records. + echo -e "\t\t
    \n\t\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 + + # 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 + 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 + echo -en "rel='noopener noreferrer'>$filename" >> $mainpage + if [[ $photo == *".mp4" ]]; then + echo -en " [VIDEO]" >> $mainpage + fi + echo -e "
  • " >> $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 + count=$(( count + 1 )) + done + echo -e "\t\t
    " >> $subpage + + # End album listings on PHOTOS page. + 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 + echo -e "

    Back

    \n\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 + 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
    " >> $subpage - fi - count=$(( count + 1 )) done - echo -e "\t\t" >> $subpage - # End album listings on PHOTOS page. - 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" >> $allpage + echo -e "

    Back

    \n\t\t
    " >> $allpage - # Add a final back button - echo -en "\n\t\t
    \n\t\t\t" >> $subpage - echo -e "

    Back

    \n\t\t
    " >> $subpage + # Finish the ALL page. + $HELPER_DIR/body_close.php >> $allpage + echo "" >> $allpage + remove_problem_strings $allpage +} - # Close out the ALBUM's page. - $HELPER_DIR/body_close.php >> $subpage - echo "" >> $subpage - - remove_problem_strings $subpage -done - -# Finish the web page. -$HELPER_DIR/body_close.php >> $mainpage -echo "" >> $mainpage - -remove_problem_strings $mainpage +## Main ## +start_main_page +build_album_pages +build_all_page +end_main_page cat $mainpage exit 0 -- 2.49.0 From b35856fa88ea5d195f465f61fa65041726ffda1d Mon Sep 17 00:00:00 2001 From: Hyperling Date: Mon, 26 May 2025 15:20:14 -0700 Subject: [PATCH 02/14] Add the folder for `all` images. --- files/photos/all/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 files/photos/all/README.md diff --git a/files/photos/all/README.md b/files/photos/all/README.md new file mode 100644 index 0000000..6f2bbc2 --- /dev/null +++ b/files/photos/all/README.md @@ -0,0 +1,3 @@ +# Hyperling.com - files/photos/all/ + +Used by `http://localhost:8080/photos` to show all albums at once. -- 2.49.0 From 474c258a83b2d7ce13b5cd22da16965ebf7c6174 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Mon, 26 May 2025 15:24:40 -0700 Subject: [PATCH 03/14] Fix syntax error preventing page from running. --- pages/photos.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/photos.sh b/pages/photos.sh index 0663846..f205a4a 100755 --- a/pages/photos.sh +++ b/pages/photos.sh @@ -207,7 +207,7 @@ function build_all_page { media="${media}" media="${media}Your browser does not support videos." media="${media}" - elif [[ $media_name == *".md" || $media_name == *".txt"]]; then + elif [[ $media_name == *".md" || $media_name == *".txt" ]]; then media="

    `cat $media_file`

    " fi -- 2.49.0 From c6fd3f4786f6aff62658875a911d21c1af7d6798 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Mon, 26 May 2025 16:38:34 -0700 Subject: [PATCH 04/14] Finish the `all` page! Even easier than expected and works GREAT! --- pages/photos.sh | 84 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 22 deletions(-) diff --git a/pages/photos.sh b/pages/photos.sh index f205a4a..3e6599e 100755 --- a/pages/photos.sh +++ b/pages/photos.sh @@ -6,6 +6,7 @@ DIR=`dirname $0` header="\n\t
    \n\t\tALBUM\n\t
    \n\t" footer="\n\t\n" +a="a target='_blank' rel='noopener noreferrer'" ## Functions ## function remove_problem_strings { @@ -48,6 +49,12 @@ function start_main_page { echo -e "video name to pull up the full resolution for download.

    " >> $mainpage echo -e "\t\t\t" >> $mainpage echo -e "\t\t" >> $mainpage + + 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
    " >> $mainpage echo -en "\t\t\t

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

    " >> $mainpage + echo -en "<$a href='/files/photos/$album/index.html'>" >> $mainpage + echo -e "$album_name" >> $mainpage echo -e "\t\t
    " >> $mainpage # Catch all the upcoming photo records. @@ -115,8 +122,7 @@ function build_album_pages { echo -e "\t\t\t\t

    `cat $photo`

    " >> $mainpage else # Otherwise put in the PHOTOS page list. - echo -en "\t\t\t\t
  • > $mainpage - echo -en "rel='noopener noreferrer'>$filename" >> $mainpage + echo -en "\t\t\t\t
  • <$a href='/$photo'>$filename" >> $mainpage if [[ $photo == *".mp4" ]]; then echo -en " [VIDEO]" >> $mainpage fi @@ -134,8 +140,7 @@ function build_album_pages { fi # Add the container for the image and its text. echo -e "\t\t\t
    " >> $subpage - echo -en "\t\t\t\t> $subpage - echo -e "rel='noopener noreferrer'>" >> $subpage + echo -en "\t\t\t\t<$a href='/$photo'>" >> $subpage # Determine what type of media it is, and how to display it. if [[ $photo == *".mp4" ]]; then echo -e "\t\t\t\t\t
    " >> $allpage + echo -e "\t\t
    " >> $allpage fi # Add a column. - echo "
    " >> $allpage + echo -e "\t\t\t
    " >> $allpage # Add the image. - echo "$media" >> $allpage + echo -e "\t\t\t\t
    " >> $allpage + echo -e "\t\t\t\t\t<$a href='$media_uri'>$media" >> $allpage + echo -e "\t\t\t\t
    " >> $allpage # Add the URLs. - echo "$media_name" >> $allpage + echo -e "\t\t\t\t
    " >> $allpage + echo -e "\t\t\t\t\t

    <$a href='$dir_uri'>$dir_name

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

    <$a href='$media_uri'>$media_name

    " >> $allpage + echo -e "\t\t\t\t
    " >> $allpage # Close the column. - echo "
    " >> $allpage + echo -e "\t\t\t
    " >> $allpage # Close the row and reset the the count if full. if [[ $count == 3 ]]; then - echo "
    " >> $allpage + echo -e "\t\t
    " >> $allpage count=0 + else + count=$(( count + 1 )) fi done -- 2.49.0 From c7f4613d220ff8211c71483250957651bc89eb93 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Mon, 26 May 2025 16:38:54 -0700 Subject: [PATCH 05/14] Delete the index files on each restart. --- run.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/run.sh b/run.sh index 5df6188..adf5d8d 100755 --- a/run.sh +++ b/run.sh @@ -75,6 +75,10 @@ done echo "`date` - Check if any node modules need updated/installed." npm install +# Reset generated index files. +echo "`date` - Removing old index files." +find files/photos/ -name "*".html -print -delete + ## Main ## echo "`date` - Start website API." -- 2.49.0 From 6fd8525dad78b29e5aa2aaa2473f593bb8d6e3ad Mon Sep 17 00:00:00 2001 From: Hyperling Date: Mon, 26 May 2025 16:39:15 -0700 Subject: [PATCH 06/14] Properly handle `jpeg` and `md` files. --- main.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index cef8888..086746a 100755 --- a/main.js +++ b/main.js @@ -212,7 +212,8 @@ async function main() { case "apk": mime = "application/vnd.android.package-archive"; break; - case "jpg" || "jpeg": + case "jpg": + case "jpeg": mime = "image/jpeg"; break; case "png": @@ -224,7 +225,9 @@ async function main() { case "zip": mime = "application/zip"; break; - case "txt" || "csv" || "md": + case "md": + case "txt": + case "csv": mime = "text/*"; break; default: -- 2.49.0 From add3a2865c7a848f6e069e886f7474cd325c6c7e Mon Sep 17 00:00:00 2001 From: Hyperling Date: Mon, 26 May 2025 18:53:19 -0700 Subject: [PATCH 07/14] Automatically reload the `/photos/` index files. --- run.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/run.sh b/run.sh index adf5d8d..ced1bcd 100755 --- a/run.sh +++ b/run.sh @@ -78,6 +78,16 @@ npm install # Reset generated index files. echo "`date` - Removing old index files." find files/photos/ -name "*".html -print -delete +{ + http_code=0 + while [[ $http_code != "200" ]]; do + sleep 1 + echo "`date` - Checking if /photos/ is ready yet." + http_code="`curl --silent --fail --w '\n%{http_code}' localhost:8080/photos | tail -n 1`" + echo "`date` - Check for /photos/ responded with '$http_code'." + done + echo "`date` - Finished loading /photos/." +} & ## Main ## -- 2.49.0 From e13a1633dddb7683b13bdc12a901df99ff461b50 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Tue, 27 May 2025 10:40:39 -0700 Subject: [PATCH 08/14] Remove unused variables. --- pages/photos.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/pages/photos.sh b/pages/photos.sh index 3e6599e..6bab140 100755 --- a/pages/photos.sh +++ b/pages/photos.sh @@ -4,8 +4,6 @@ ## Static Variables ## DIR=`dirname $0` -header="\n\t
    \n\t\tALBUM\n\t
    \n\t" -footer="\n\t\n" a="a target='_blank' rel='noopener noreferrer'" ## Functions ## -- 2.49.0 From 55742e50db0ea9fceedaecee70663e9a0716fed5 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Tue, 27 May 2025 10:51:41 -0700 Subject: [PATCH 09/14] Remove the `all` folder in place of an `all.html` file. Create a main page which provides the output of it. --- files/photos/README.md | 8 +++++++- files/photos/all/README.md | 3 --- pages/photos-all.sh | 20 ++++++++++++++++++++ pages/photos.sh | 6 +++--- 4 files changed, 30 insertions(+), 7 deletions(-) delete mode 100644 files/photos/all/README.md create mode 100755 pages/photos-all.sh diff --git a/files/photos/README.md b/files/photos/README.md index 118a7ff..4bc762a 100644 --- a/files/photos/README.md +++ b/files/photos/README.md @@ -1,3 +1,9 @@ # Hyperling.com - files/photos/ -Used by `http://localhost:8080/photos` to build albums for sharing. +## index.html + +Used by `http://localhost:8080/photos` to build and show list of albums. + +## all.html + +Used by `http://localhost:8080/photos-all` to show all albums at once. diff --git a/files/photos/all/README.md b/files/photos/all/README.md deleted file mode 100644 index 6f2bbc2..0000000 --- a/files/photos/all/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Hyperling.com - files/photos/all/ - -Used by `http://localhost:8080/photos` to show all albums at once. diff --git a/pages/photos-all.sh b/pages/photos-all.sh new file mode 100755 index 0000000..68024a8 --- /dev/null +++ b/pages/photos-all.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Alias for new All Photos feed. + +# Move to main directory. +DIR=`dirname $0` +cd $DIR/.. + +# Locations of photo scripts. +photos_all=./files/photos/all.html +photos=./pages/photos.sh + +# If the all script does not exist,call the generator and ignore its output. +if [[ ! -e $photos_all ]]; then + $photos > /dev/null +fi + +## Main ## +cat $photos_all + +exit 0 diff --git a/pages/photos.sh b/pages/photos.sh index 6bab140..b0a1706 100755 --- a/pages/photos.sh +++ b/pages/photos.sh @@ -19,7 +19,7 @@ cd $DIR/.. HELPER_DIR=./pages/helpers PHOTOS_DIR=./files/photos mainpage=$PHOTOS_DIR/index.html -allpage=$PHOTOS_DIR/all/index.html +allpage=$PHOTOS_DIR/all.html # Use the cached version if available. if [[ -e $mainpage ]]; then @@ -49,7 +49,7 @@ function start_main_page { echo -e "\t\t
    " >> $mainpage echo -e "\t\t
    " >> $mainpage - echo -e "\t\t\t<$a href='/files/photos/all/index.html'" >> $mainpage + echo -e "\t\t\t<$a href='/photos-all'" >> $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 @@ -194,7 +194,7 @@ function build_all_page { # Add header. echo -e "\t\t
    " >> $allpage - echo -e "\t\t\t

    All Image Feed

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

    All Photo Feed

    " >> $allpage echo -e "\t\t
    " >> $allpage # Add images to the page -- 2.49.0 From fcb091a16465e5ed249054846fd016759f5b952a Mon Sep 17 00:00:00 2001 From: Hyperling Date: Tue, 27 May 2025 10:53:19 -0700 Subject: [PATCH 10/14] Change name of the page to Full Photo Feed from Full Image Feed. --- pages/photos.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pages/photos.sh b/pages/photos.sh index b0a1706..0709a43 100755 --- a/pages/photos.sh +++ b/pages/photos.sh @@ -50,7 +50,7 @@ function start_main_page { echo -e "\t\t
    " >> $mainpage echo -e "\t\t\t<$a href='/photos-all'" >> $mainpage - echo -e "\t\t\t\tclass='col-12 header'>Click Here for the Full Image Feed" >> $mainpage + echo -e "\t\t\t\tclass='col-12 header'>Click Here for the Full Photo Feed" >> $mainpage echo -e "\t\t\t" >> $mainpage echo -e "\t\t
    " >> $mainpage } @@ -180,7 +180,7 @@ function build_album_pages { done } -## Create an ALL page at /photos/all/ ## +## Create an ALL page. ## function build_all_page { # - Shows all photos in descending order, as an overall feed. # - Four images wide. @@ -201,7 +201,6 @@ function build_all_page { find $PHOTOS_DIR/ ! -name "*".html | sort -r | while read media_file; do if [[ -d $media_file || "$media_file" == *"/photos/README.md" - || "$media_file" == *"/all/README.md" ]]; then continue fi -- 2.49.0 From b4d9bae24669e580694d44d843369fa1af50a996 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Tue, 27 May 2025 11:20:20 -0700 Subject: [PATCH 11/14] Add log function to ensure consistent output. Enhance regeneration of photo index files. --- run.sh | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/run.sh b/run.sh index ced1bcd..0d1542f 100755 --- a/run.sh +++ b/run.sh @@ -21,6 +21,11 @@ function usage { exit $1 } +function log { + message="$1" + echo -e "`date` - $message" +} + ## Parameters ## while getopts ':p:h' opt; do @@ -43,11 +48,11 @@ cd $DIR sudo="" if [[ $LOGNAME != "root" ]]; then - echo "`date` - Using sudo since user is '$LOGNAME'." + log "Using sudo since user is '$LOGNAME'." sudo="sudo" fi -echo "`date` - Check if any system dependencies need installed." +log "Check if any system dependencies need installed." if [[ ! `which php` ]]; then echo "- Installing PHP" $sudo apt-get install -y php-cli @@ -62,7 +67,7 @@ if [[ ! `which npm` ]]; then fi # Directories and allowed page types are executable, others are not. -echo "`date` - Fix any strange file permissions." +log "Fix any strange file permissions." find ./pages/ | while read file; do if [[ $file == *".php" || $file == *".sh" || -d $file ]]; then mode=755 @@ -72,30 +77,43 @@ find ./pages/ | while read file; do chmod -c $mode $file done -echo "`date` - Check if any node modules need updated/installed." +log "Check if any node modules need updated/installed." npm install # Reset generated index files. -echo "`date` - Removing old index files." +log "Removing old index files." find files/photos/ -name "*".html -print -delete { + count=1 http_code=0 + port="${ports%% *}" + if [[ -z $port ]]; then + port="8080" + fi + photos_uri=":$port/photos/" while [[ $http_code != "200" ]]; do - sleep 1 - echo "`date` - Checking if /photos/ is ready yet." - http_code="`curl --silent --fail --w '\n%{http_code}' localhost:8080/photos | tail -n 1`" - echo "`date` - Check for /photos/ responded with '$http_code'." + log "Sleeping for '$count' while waiting for $photos_uri to come up." + sleep $count + log "Checking if $photos_uri is available." + http_code="`curl --silent --fail --w '\n%{http_code}' localhost$photos_uri | tail -n 1`" + log "Check for $photos_uri responded with '$http_code'." + if (( $count >= 10 )); then + log "Giving up on loading $photos_uri after '$count' attempts." + break + else + count=$(( count + 1 )) + fi done - echo "`date` - Finished loading /photos/." + log "Finished checking for /photos/." } & ## Main ## -echo "`date` - Start website API." +log "Start website API." node ./main.js $ports status=$? ## Finish ## -echo "`date` - Exiting with status '$status'." +log "Exiting with status '$status'." exit $status -- 2.49.0 From aa20bd67ee72aa0f8072fcf7b9b89fee89fd70ea Mon Sep 17 00:00:00 2001 From: Hyperling Date: Tue, 27 May 2025 11:27:06 -0700 Subject: [PATCH 12/14] Add TBD's of how to better output in the log. --- main.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.js b/main.js index 086746a..f44b4de 100755 --- a/main.js +++ b/main.js @@ -141,6 +141,7 @@ async function main() { /* AUTOMATIC METHOD BASED ON OBJECT/ARRAY OF WEB SCRIPTS // Creates routes with the URL of the key and location of the value. */ + // TBD/TODO would be great to log this as "DATE: ADDRESS hit ROUTER requesting RESOURCE" for (let key in pages) { console.log(" * Creating router for", key); router.get("/" + key, function (req,res) { @@ -182,6 +183,7 @@ async function main() { `; // Provide sitemap.xml file for "SEO". + // TBD/TODO would be great to log this as "DATE: ADDRESS hit ROUTER requesting RESOURCE" console.log(" * Creating router for sitemap.xml"); router.get('/sitemap.xml', function (req, res) { console.log("sitemap.xml being provided to", req.socket.remoteAddress) @@ -190,6 +192,7 @@ async function main() { }); // Provide human-usable sitemap links. + // TBD/TODO would be great to log this as "DATE: ADDRESS hit ROUTER requesting RESOURCE" console.log(" * Creating router for sitemap*"); router.get('/sitemap*', function (req, res) { console.log("sitemap.html being provided to", req.socket.remoteAddress) @@ -197,6 +200,7 @@ async function main() { }); // Return a resource from the files folder. + // TBD/TODO would be great to log this as "DATE: ADDRESS hit ROUTER requesting RESOURCE" console.log(" * Creating router for files"); router.get('/files*', function (req, res) { console.log("file response to", req.socket.remoteAddress, "asking for", req.url) -- 2.49.0 From 18cd38b194b3024f05370eb9a744388ef5c931a2 Mon Sep 17 00:00:00 2001 From: Hyperling Date: Tue, 27 May 2025 11:27:18 -0700 Subject: [PATCH 13/14] Add default port in this script. --- run.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/run.sh b/run.sh index 0d1542f..4de0cfe 100755 --- a/run.sh +++ b/run.sh @@ -41,6 +41,10 @@ while getopts ':p:h' opt; do esac done +if [[ -z $ports ]]; then + ports=8080 +fi + ## Build Environment ## # Ensure we are executing from this file's directory. @@ -87,9 +91,6 @@ find files/photos/ -name "*".html -print -delete count=1 http_code=0 port="${ports%% *}" - if [[ -z $port ]]; then - port="8080" - fi photos_uri=":$port/photos/" while [[ $http_code != "200" ]]; do log "Sleeping for '$count' while waiting for $photos_uri to come up." -- 2.49.0 From 073377532e4efae66f3f36dded3c95843d52ea1c Mon Sep 17 00:00:00 2001 From: Hyperling Date: Tue, 27 May 2025 12:41:17 -0700 Subject: [PATCH 14/14] Add headers to all pages! Also update the look and feel of the `test` page. --- pages/about.php | 3 +++ pages/apps.php | 3 +++ pages/contact.php | 3 +++ pages/donate.php | 3 +++ pages/health.php | 3 +++ pages/helpers/header.php | 9 ++++++++- pages/home.php | 3 +++ pages/journey.sh | 2 +- pages/lists.php | 3 +++ pages/media.php | 3 +++ pages/photos.sh | 4 ++++ pages/resume.php | 3 +++ pages/support.php | 3 +++ pages/test.sh | 40 +++++++++++++++++++++++----------------- pages/videos.php | 3 +++ 15 files changed, 69 insertions(+), 19 deletions(-) diff --git a/pages/about.php b/pages/about.php index a626e30..0781d5a 100755 --- a/pages/about.php +++ b/pages/about.php @@ -1,5 +1,8 @@ #!/usr/bin/php diff --git a/pages/apps.php b/pages/apps.php index 97405c5..7b98f22 100755 --- a/pages/apps.php +++ b/pages/apps.php @@ -3,5 +3,8 @@ Synonym for home page. --> diff --git a/pages/contact.php b/pages/contact.php index 40d4125..a315c8e 100755 --- a/pages/contact.php +++ b/pages/contact.php @@ -1,5 +1,8 @@ #!/usr/bin/php diff --git a/pages/donate.php b/pages/donate.php index 2aabe91..7304fc8 100755 --- a/pages/donate.php +++ b/pages/donate.php @@ -3,5 +3,8 @@ Alias for the support page with a more common name. --> diff --git a/pages/health.php b/pages/health.php index 21e75c2..de0ec0d 100755 --- a/pages/health.php +++ b/pages/health.php @@ -4,6 +4,9 @@ --> diff --git a/pages/helpers/header.php b/pages/helpers/header.php index 352a717..4f2350b 100755 --- a/pages/helpers/header.php +++ b/pages/helpers/header.php @@ -1,8 +1,15 @@ #!/usr/bin/php + - Hyperling + Hyperling<?php echo($GLOBALS["HEADER_TITLE"]); ?> diff --git a/pages/home.php b/pages/home.php index 9d71f09..66631fc 100755 --- a/pages/home.php +++ b/pages/home.php @@ -3,6 +3,9 @@ Landing page, keeping it apps and development projects like old WordPress site. --> diff --git a/pages/journey.sh b/pages/journey.sh index 23e01f2..b0db2f3 100755 --- a/pages/journey.sh +++ b/pages/journey.sh @@ -4,7 +4,7 @@ cd `dirname $0` # Create the necessary HTML components for a web page. -./helpers/body_open.php +./helpers/body_open.php | sed -e 's/Hyperling/Hyperling: Journey/' #Content for this page cat << EOF diff --git a/pages/lists.php b/pages/lists.php index d8377ea..ec87496 100755 --- a/pages/lists.php +++ b/pages/lists.php @@ -3,6 +3,9 @@ Lists of items which I'd like to share such as gear and frequently used apps. --> diff --git a/pages/media.php b/pages/media.php index 74112e7..4c91a82 100755 --- a/pages/media.php +++ b/pages/media.php @@ -3,6 +3,9 @@ Page for my video links. --> diff --git a/pages/photos.sh b/pages/photos.sh index 0709a43..2924752 100755 --- a/pages/photos.sh +++ b/pages/photos.sh @@ -32,6 +32,7 @@ fi function start_main_page { # Create the necessary HTML components for a web page. $HELPER_DIR/body_open.php > $mainpage + sed -i -e 's/Hyperling/Hyperling: Photos/' $mainpage echo "" >> $mainpage # Give the page a description. @@ -89,6 +90,8 @@ function build_album_pages { page="" subpage="$PHOTOS_DIR/$album/index.html" $HELPER_DIR/body_open.php > $subpage + sed -i -e "s/Hyperling/Hyperling: $album_name/" $subpage + echo "" >> $subpage # Add a back button echo -en "\n\t\t
    \n\t\t\t" >> $subpage @@ -190,6 +193,7 @@ function build_all_page { # Create/overwrite file. $HELPER_DIR/body_open.php > $allpage + sed -i -e 's/Hyperling/Hyperling: All Photos/' $allpage echo "" >> $allpage # Add header. diff --git a/pages/resume.php b/pages/resume.php index ca8de98..b385119 100755 --- a/pages/resume.php +++ b/pages/resume.php @@ -3,6 +3,9 @@ Page for my resume and work skill links. --> diff --git a/pages/support.php b/pages/support.php index edcd146..42e3c42 100755 --- a/pages/support.php +++ b/pages/support.php @@ -3,6 +3,9 @@ Page to provide ways people can support me. --> diff --git a/pages/test.sh b/pages/test.sh index 2a73aa2..5d97740 100755 --- a/pages/test.sh +++ b/pages/test.sh @@ -4,27 +4,33 @@ cd `dirname $0` # Create the necessary HTML components for a web page. -./helpers/body_open.php -echo -e "\t\t

    This is a web page written in BASH!!!

    " +./helpers/body_open.php | sed -e 's/Hyperling/Hyperling: Test Page!/' +echo -e "\t\t
    " +echo -e "\t\t\t

    This is a web page written in BASH!!!

    " + cat << EOF -

    - Look at all the fancy things we can do! -

    -

    Current Time

    -

    - We can use the date command to spit out the time! -

    -

    - `date` -

    +

    + Look at all the fancy things we can do! +

    + +

    Current Time

    +
    +

    + We can use the date command to spit out the time! +

    +

    + `date` +

    +
    EOF # Create a subsection -echo -e "\t\t

    Server Neofetch

    " -echo -e "\t\t

    " -#neofetch --stdout -echo "jk lol" -echo -e "\t\t

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

    Server Neofetch

    " +echo -en "\t\t\t

    " +#neofetch --stdout | sed -e 's/\n/
    /g' +echo -n "jk lol" +echo -e "

    " +echo -e "\t\t
    " # Finish the web page ./helpers/body_close.php diff --git a/pages/videos.php b/pages/videos.php index 160eaa5..5d1159a 100755 --- a/pages/videos.php +++ b/pages/videos.php @@ -4,5 +4,8 @@ Deprecated 2024-03-06 for /media. --> -- 2.49.0