From 3d784cc5bcc7dd4a2d09794390229cfd89568ec2 Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Sun, 2 Dec 2018 20:24:13 -0500 Subject: [PATCH] cosmic-web matches gopherspace --- bin/cosmic-web | 82 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/bin/cosmic-web b/bin/cosmic-web index b0c2176..e877d06 100755 --- a/bin/cosmic-web +++ b/bin/cosmic-web @@ -1,11 +1,41 @@ #!/bin/sh +entry_index () { + line="$1" + index=$2 + log=$(printf "%s" "$line" | awk -F'\t' '{print $2}') + loghtml=$(printf "%s" "$log" | sed 's/\.[^.]*$//') + logdir=$(dirname "$log") + title=$(printf "%s" "$line" | awk -F'\t' '{print $1}' | sed 's|^.||') + + # print link in listings + if [ $index -lt 20 ]; then + printf ">> %s\\n" "$loghtml" "$title" >> "${file_html}" + fi + printf ">> %s\\n" "$loghtml" "$title" >> "${log_html}" + + # create entry + entry_html="${html_dir}${loghtml}.html" + mkdir -p "${html_dir}${logdir}" + cat "$web_header_html" > "${entry_html}" + { + printf " %s\\n" "$title" + printf " \\n" "$loghtml" + printf "\\n\\n
\\n"
+    printf "<< BACK TO RELAY ONE LOG\\n\\n\\n"
+    sed 's/&/\&/g; s//\>/g; s/"/\"/g; s/'"'"'/\'/g' "${gopher_dir}${log}"
+    # close up the entry footer
+    printf "
" + } >> "${entry_html}" +} + run_user=$(id -u) if [ "$run_user" -eq 0 ]; then SCRIPT=$(readlink -f "$0") SCRIPTPATH=$(dirname "$SCRIPT") file_html="/var/www/html/index.html" + log_html="/var/www/html/log/index.html" web_header_html="${SCRIPTPATH}/../templates/webheader.tmpl" ships_html="/var/www/html/ships/index.html" error_html="/var/www/html/error.html" @@ -18,8 +48,13 @@ if [ "$run_user" -eq 0 ]; then # shellcheck source=cosmic-rss . "${SCRIPTPATH}/cosmic-rss" + # prep directories + mkdir -p "$(dirname "${log_html}")" + # Add standard header cat "$web_header_html" > "${file_html}" + cat "$web_header_html" > "${log_html}" + # Custom header elements and body start { printf "Cosmic Voyage" @@ -32,32 +67,31 @@ if [ "$run_user" -eq 0 ]; then # Intro text cat "${gopher_dir}/intro.gophermap" # Ship listings - printf "\\n>> Ships, Colonies, Outposts\\n\\n" + printf "\\n>> Ships, Colonies, Outposts\\n" + printf ">> Transmission Log\\n" + printf ">> RSS Feed\\n\\n" # Logs - printf "Transmission Log:\\n" + printf "Most recent log entries:\\n" } >> "${file_html}" - # Loop through listings gophermap - while read -r line; do - log=$(printf "%s" "$line" | awk -F'\t' '{print $2}') - loghtml=$(printf "%s" "$log" | sed 's/\.[^.]*$//') - logdir=$(dirname "$log") - title=$(printf "%s" "$line" | awk -F'\t' '{print $1}' | sed 's|^.||') - # print link in listings - printf ">> %s\\n" "$loghtml" "$title" >> "${file_html}" - # create entry - entry_html="${html_dir}${loghtml}.html" - mkdir -p "${html_dir}${logdir}" - cat "$web_header_html" > "${entry_html}" - { - printf " %s\\n" "$title" - printf " \\n" "$loghtml" - printf "\\n\\n
\\n"
-      printf "<< BACK TO RELAY ONE\\n\\n\\n"
-      sed 's/&/\&/g; s//\>/g; s/"/\"/g; s/'"'"'/\'/g' "${gopher_dir}${log}"
-      # close up the entry footer
-      printf "
" - } >> "${entry_html}" + # Custom header elements and body start + { + printf "Cosmic Voyage - Transmission Log" + printf "" + printf "" + printf "" + printf "
" + printf "
"
+    printf "<< BACK TO RELAY ONE\\n\\n"
+    # Intro text
+    cat "${gopher_dir}/log/intro.gophermap"
+  } >> "${log_html}" 
+
+  # Loop through listings gophermap
+  loop=0
+  while read -r line; do
+    loop=$((loop+1))
+    entry_index "$line" $loop
   done < "${gopher_dir}/listing.gophermap"
   # footer
   {
@@ -65,7 +99,7 @@ if [ "$run_user" -eq 0 ]; then
     printf "
\\n" printf "\\n" printf "" - } >> "${file_html}" + } | tee -a "${log_html}" >> "${file_html}" # Generate ship pages mkdir -p "${html_dir}/ships"