]> git.plutz.net Git - shellwiki/commitdiff
allow page content from stdin for easyer theming of special pages
authorPaul Hänsch <paul@plutz.net>
Mon, 23 May 2022 09:38:09 +0000 (11:38 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 23 May 2022 09:38:09 +0000 (11:38 +0200)
themes/default.sh

index e9e9d73f195466c6bfcf2433dfe0dcb8767aab60..1f8d285d4eb9a241601dde074f0fbd80fcb66800 100755 (executable)
@@ -24,15 +24,18 @@ theme_pagemenu(){
   if acl_write "$page"; then
     printf  '
     <ul class="pagemenu">
-      <li><a href="[edit]">Edit</a></li>
-      <li><a href="[attachment]/">Attachments</a></li>
+      <li><a href="./">View</a></li>
+      <li><a href="./[edit]">Edit</a></li>
+      <li><a href="./[attachment]">Attachments</a></li>
+      <li><a href="./[revision]">Revisions</a></li>
     </ul>'
   fi
 }
 
 theme_page(){
-  local page="$1" title
-  title="${page%/}"; title="${title##*/}"
+  local page="$1" title="$2" id="$3"
+  title="$(HTML "${title:-"${page}"}")"
+  id="$(HTML "${id:-"${page}"}")"
 
   # Important! Web Server response including newline
   printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
@@ -41,14 +44,18 @@ theme_page(){
        <!DOCTYPE HTML>
        <html><head>
          $(theme_head)
-         <title>$(HTML "${title}")</title>
-       </head><body id="$(HTML "$page")">
+         <title>${title}</title>
+       </head><body id="$id">
          $(theme_header)
          <main>
            $(theme_pagemenu)
-           <article>
-             $(wiki "$page" || printf 'Error while loading page <br> function "wiki" of index.sh returned with an error.')
-           </article>
+           $(if [ "$page" = '-' ]; then
+               cat
+             else
+               printf '<article>'
+               wiki "$page"
+               printf '</article>'
+           fi)
          </main>
          $(theme_footer)
        </body></html>
@@ -61,25 +68,14 @@ theme_editor(){
 
   [ "$template" ] && acl_read "$template" || template="$page"
 
-  # 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>$(HTML "${title}")</title>
-       </head><body id="$(HTML "$page")" class="editor">
-         $(theme_header)
-         <main><form method=POST action="$(HTML "${page%/}/[edit]")">
-           <input type=hidden name=session_key value="${SESSION_KEY}"/>
-            <textarea name=pagetext>$({ wiki_text "$page" \
-                                     || wiki_text "$template"; } |HTML)</textarea>
-            <button type=submit name=action value=update>Update</button>
-            <button type=submit name=action value=cancel>Cancel</button>
-          </form></main>
-         $(theme_footer)
-       </body></html>
+  theme_page - "Editor: $title" "${page}[edit]" <<-EOF
+       <form method=POST action="$(HTML "${page%/}/[edit]")">
+         <input type=hidden name=session_key value="${SESSION_KEY}"/>
+         <textarea name=pagetext>$({ wiki_text "$page" \
+                                  || wiki_text "$template"; } |HTML)</textarea>
+         <button type=submit name=action value=update>Update</button>
+         <button type=submit name=action value=cancel>Cancel</button>
+       </form>
        EOF
 }
 
@@ -87,88 +83,51 @@ theme_revisions(){
   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>Revisions $(HTML "${title}")</title>
-       </head><body id="$(HTML "$page")[attachment]/">
-         $(theme_header)
-         <main>
-         $("$_EXEC/macros/revisions" "$page")
-         </main>
-         $(theme_footer)
-       </body></html>
-       EOF
+ "$_EXEC/macros/revisions" "$page" \
+  | theme_page - "Revisions: $title" "${page}[revision]"
 }
 
 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" ""
-
   if acl_write "$page"; then
-    cat <<-EOF
-       <!DOCTYPE HTML>
-       <html><head>
-         $(theme_head)
-         <title>Attachments $(HTML "${title}")</title>
-       </head><body id="$(HTML "$page")[attachment]/">
-         $(theme_header)
-         <main>
-           <form class=upload method=POST enctype="multipart/form-data">
-             <input type=hidden name=session_id value="$SESSION_ID">
-             <input type=file name=file multiple>
-             <button type=submit name=action value=upload>Upload</button>
-           </form>
-
-            <form method=POST><ul class="attachment list">
-             <input type=hidden name=session_key value="$SESSION_KEY">
-           $(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><button type=submit name=delete value="%s">Delete</button><a class=name href="%s">%s</a>
-                     <span class=size>%s</span><span class=date>%s</span></li>' \
-               "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" \
-               "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
-           done)
-            </ul></form>
-         </main>
-         $(theme_footer)
-       </body></html>
+    theme_page - "Attachments: $title" "${page}[attachment]" <<-EOF
+       <form class=upload method=POST enctype="multipart/form-data">
+         <input type=hidden name=session_id value="$SESSION_ID">
+         <input type=file name=file multiple>
+         <button type=submit name=action value=upload>Upload</button>
+       </form>
+       
+       <form method=POST><ul class="attachment list">
+         <input type=hidden name=session_key value="$SESSION_KEY">
+       $(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><button type=submit name=delete value="%s">Delete</button><a class=name href="%s">%s</a>
+                 <span class=size>%s</span><span class=date>%s</span></li>' \
+           "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" \
+           "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
+       done)
+       </ul></form>
        EOF
   else
-    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><a class=name href="%s">%s</a>
-                     <span class=size>%s</span><span class=date>%s</span></li>' \
-               "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
-           done)
-            </ul>
-         </main>
-         $(theme_footer)
-       </body></html>
+    theme_page - "Attachments: $title" "${page}[attachment]" <<-EOF
+       <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><a class=name href="%s">%s</a>
+                 <span class=size>%s</span><span class=date>%s</span></li>' \
+           "$(HTML "${file##*/}")" "$(HTML "${file##*/}")" "$(size_human "$size")" "$(date -d @"$date" +"%F %T")"
+       done)
+       </ul>
        EOF
   fi
 }