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/main.js b/main.js index cef8888..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) @@ -212,7 +216,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 +229,9 @@ async function main() { case "zip": mime = "application/zip"; break; - case "txt" || "csv" || "md": + case "md": + case "txt": + case "csv": mime = "text/*"; break; default: 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-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 c094b7e..2924752 100755 --- a/pages/photos.sh +++ b/pages/photos.sh @@ -2,12 +2,11 @@ # 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" +a="a target='_blank' rel='noopener noreferrer'" -# Functions +## Functions ## function remove_problem_strings { file="$1" sed -i -e 's/#!\/usr\/bin\/php//g' $file @@ -20,6 +19,7 @@ cd $DIR/.. HELPER_DIR=./pages/helpers PHOTOS_DIR=./files/photos mainpage=$PHOTOS_DIR/index.html +allpage=$PHOTOS_DIR/all.html # Use the cached version if available. if [[ -e $mainpage ]]; then @@ -28,146 +28,273 @@ 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 + sed -i -e 's/Hyperling/Hyperling: Photos/' $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 - - # 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 - - # 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
    " >> $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 - # Add a final back button - echo -en "\n\t\t
    \n\t\t\t" >> $subpage - echo -e "

    Back

    \n\t\t
    " >> $subpage + 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 Photo Feed" >> $mainpage + echo -e "\t\t\t" >> $mainpage + echo -e "\t\t
    " >> $mainpage +} - # Close out the ALBUM's page. - $HELPER_DIR/body_close.php >> $subpage - echo "" >> $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 +} - remove_problem_strings $subpage -done +## 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" || "$album" == "all" ]]; then + continue + fi -# Finish the web page. -$HELPER_DIR/body_close.php >> $mainpage -echo "" >> $mainpage + # 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 "<$a href='/files/photos/$album/index.html'>" >> $mainpage + echo -e "$album_name

    " >> $mainpage + echo -e "\t\t
    " >> $mainpage -remove_problem_strings $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 + sed -i -e "s/Hyperling/Hyperling: $album_name/" $subpage + echo "" >> $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 + + # 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
  • <$a href='/$photo'>$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 + # Add the container for the image and its text. + echo -e "\t\t\t
    " >> $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" >> $subpage + elif [[ $photo == *".md" || $photo == *".txt" ]]; then + echo -e "\t\t\t\t\t

    `cat $photo`

    " >> $subpage + else + echo -e "\t\t\t\t\t" >> $subpage + 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" >> $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. ## +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 + sed -i -e 's/Hyperling/Hyperling: All Photos/' $allpage + echo "" >> $allpage + + # Add header. + echo -e "\t\t
    " >> $allpage + echo -e "\t\t\t

    All Photo Feed

    " >> $allpage + echo -e "\t\t
    " >> $allpage + + # Add images to the page + find $PHOTOS_DIR/ ! -name "*".html | sort -r | while read media_file; do + if [[ -d $media_file + || "$media_file" == *"/photos/README.md" + ]]; then + continue + fi + + # Remove the initial '.' from the URI. + media_uri="${media_file//\.\//\/}" + + # Path to the image home. + dir_uri="`dirname $media_uri`" + + # Prepare variables which will be used throughout the loop. + media_name="`basename $media_uri`" + dir_name="`basename $dir_uri`" + + # This must be after the dir_name has been pulled. + dir_uri="$dir_uri/index.html" + + # Do not show the file extension for the filename. + media_name="${media_name%%.*}" + + # Change underscores and dashes to be spaces for better overflow. + media_name="${media_name//_/ }" + media_name="${media_name//-/ }" + dir_name="${dir_name//_/ }" + dir_name="${dir_name//-/ }" + + media="" + + # Determine how to show the file. + if [[ $media_uri == *".mp4" ]]; then + media="" + media_name="$media_name [VIDEO]" + elif [[ $media_uri == *".md" || $media_uri == *".txt" ]]; then + media="

    `cat $media_file`

    " + fi + + # Add a row if count has reset. + if [[ -z $count ]]; then + count=0 + fi + if [[ $count == 0 ]]; then + echo -e "\t\t
    " >> $allpage + fi + + # Add a column. + echo -e "\t\t\t
    " >> $allpage + + # Add the image. + 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 -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 -e "\t\t\t
    " >> $allpage + + # Close the row and reset the the count if full. + if [[ $count == 3 ]]; then + echo -e "\t\t
    " >> $allpage + count=0 + else + count=$(( count + 1 )) + fi + done + + # Add a final back button. + echo -en "\n\t\t
    \n\t\t\t" >> $allpage + echo -e "

    Back

    \n\t\t
    " >> $allpage + + # Finish the ALL page. + $HELPER_DIR/body_close.php >> $allpage + echo "" >> $allpage + remove_problem_strings $allpage +} + +## Main ## +start_main_page +build_album_pages +build_all_page +end_main_page cat $mainpage exit 0 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. --> diff --git a/run.sh b/run.sh index 5df6188..4de0cfe 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 @@ -36,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. @@ -43,11 +52,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 +71,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,16 +81,40 @@ 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. +log "Removing old index files." +find files/photos/ -name "*".html -print -delete +{ + count=1 + http_code=0 + port="${ports%% *}" + photos_uri=":$port/photos/" + while [[ $http_code != "200" ]]; do + 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 + 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