]> git.plutz.net Git - shellwiki/commitdiff
attachment processing, serving and overview
authorPaul Hänsch <paul@plutz.net>
Mon, 21 Mar 2022 13:59:12 +0000 (14:59 +0100)
committerPaul Hänsch <paul@plutz.net>
Mon, 21 Mar 2022 13:59:12 +0000 (14:59 +0100)
attachment.sh
index.cgi
themes/default.sh

index 68e03b9b7ab9435961ca41abbaa93e2667aced7d..b5e8491298ed398a3e7e733d37ef109c74b10405 100755 (executable)
@@ -60,7 +60,10 @@ attachment_convert(){
   esac
 }
 
-if [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then
+if [ "${PATH_INFO%/\[attachment\]/}"  != "${PATH_INFO}" ]; then
+  theme_attachments "${PATH_INFO%\[attachment\]/}"
+
+elif [ "${PATH_INFO%/\[attachment\]/*}" != "${PATH_INFO}" ]; then
   attpath="${PATH_INFO%/\[attachment\]/*}/#attachments/${PATH_INFO##*/}"
   if [ -f "$_DATA/pages/$attpath" ]; then
     FILE "$_DATA/pages/$attpath"
index ea78af168a22a187e80bfa4e1bfa302b7afa67dd..9b38362b665dffae0b6a0f59286e0aff5d8da30e 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -86,8 +86,6 @@ case "${PATH_INFO}" in
     if [ -f "$_DATA/pages/$PATH_INFO/#page.md" \
       -o -f "$_EXEC/pages/$PATH_INFO/#page.md" ]; then
       theme_page "${PATH_INFO}"
-    else
-      theme_404
     fi
     ;;
   */"[login]")
index c096f8218a03639d6b24352c4ed4228df515993d..6fa6ba16566245e9e7c0b92b883a155bf9ad4a19 100755 (executable)
@@ -1,9 +1,12 @@
 #!/bin/sh
 
+. "$_EXEC/tools.sh"
+
 theme_head(){
   printf '
   <meta name="viewport" content="width=device-width"/>
   <link rel="stylesheet" type="text/css" href="%s/[.]/cgilite/common.css">
+  <link rel="stylesheet" type="text/css" href="%s/[.]/themes/default.css">
   ' "$_BASE"
 }
 
@@ -19,7 +22,7 @@ theme_page(){
   local page="$1" title
   title="${page%/}"; title="${title##*/}"
 
-  # Important! Web Server response including newline newline
+  # Important! Web Server response including newline
   printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
 
   cat <<-EOF
@@ -29,7 +32,15 @@ theme_page(){
          <title>$(HTML "${title}")</title>
        </head><body id="$(HTML "$page")">
          $(theme_header)
-         <main>$(wiki "$page" || printf 'Page not found')</main>
+         <main>
+           <ul class="pagemenu">
+             <li><a href="[edit]">Edit</a></li>
+             <li><a href="[attachment]/">Attachments</a></li>
+           </ul>
+           <article>
+             $(wiki "$page" || printf 'Page not found')
+           </article>
+         </main>
          $(theme_footer)
        </body></html>
        EOF
@@ -60,6 +71,39 @@ theme_editor(){
        EOF
 }
 
+theme_attachments(){
+  local page="$1" title
+  title="${page%/}"; title="${title##*/}"
+
+  # Important! Web Server response including newline
+  printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
+
+  cat <<-EOF
+       <!DOCTYPE HTML>
+       <html><head>
+         $(theme_head)
+         <title>Attachments $(HTML "${title}")</title>
+       </head><body id="$(HTML "$page")[attachment]/">
+         $(theme_header)
+         <main>
+            <ul class="attachment list">
+           $(for file in "$_EXEC/pages/$page/#attachments"/* "$_DATA/pages/$page/#attachments"/*; do
+             [ "$file" = "$_EXEC/pages/$page/#attachments/${file##*/}" \
+                   -a -f "$_DATA/pages/$page/#attachments/${file##*/}" ] && continue
+             stat="$(stat -c '%s %Y' -- "$file" 2>&-)" || continue
+             size="${stat% *}" date="${stat#* }"
+           
+             printf '<li><span class=name>%s</span>
+                     <span class=size>%s</span><span class=date>%s</span></li>' \
+               "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
+           done)
+            </ul>
+         </main>
+         $(theme_footer)
+       </body></html>
+       EOF
+}
+
 theme_login(){
   theme_page '[wiki]/login/'
 }