]> git.plutz.net Git - shellwiki/blobdiff - themes/default.sh
attachment processing, serving and overview
[shellwiki] / themes / default.sh
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/'
 }