]> git.plutz.net Git - shellwiki/commitdiff
default header and footer pages
authorPaul Hänsch <paul@plutz.net>
Thu, 10 Mar 2022 16:34:01 +0000 (17:34 +0100)
committerPaul Hänsch <paul@plutz.net>
Thu, 10 Mar 2022 16:34:01 +0000 (17:34 +0100)
index.cgi
pages/[wiki]/footer/#page.md [new file with mode: 0644]
pages/[wiki]/header/#page.md [new file with mode: 0644]
themes/default.sh

index 9d2ed3d657b4f8cc16b19511c5d7a53654b361bb..76f1bef6a0062b6e71e6191a3feeb74bd990a7c2 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -4,7 +4,7 @@
 set -- nocookie
 . "${_EXEC}/cgilite/session.sh"
 . "${_EXEC}/cgilite/file.sh"
-# . "$_EXEC"/cgilite/users.sh
+. "${_EXEC}/cgilite/users.sh"
 
 . "${_EXEC}/themes/default.sh"
 
@@ -20,6 +20,20 @@ else
   md() { cat; }
 fi
 
+wiki_text() {
+  # Print source text of a wiki page
+  # Get page from data or underlay dir
+  local page="$(PATH "$1")"
+
+  if [ -f "$_DATA/pages/$page/#page.md" ]; then
+    cat -- "$_DATA/pages/$page/#page.md"
+  elif [ -f "$_EXEC/pages/$page/#page.md" ]; then
+    cat -- "$_EXEC/pages/$page/#page.md"
+  else
+    return 1
+  fi
+}
+
 wiki() {
   # Print content of a wiki page
   # Get page from data or underlay dir, handle caching
@@ -66,8 +80,8 @@ attachment() {
 }
 
 case "${PATH_INFO}" in
-  /"[wiki]"/*)
-    FILE "${_EXEC}/${PATH_INFO#/\[wiki\]}"
+  /"[.]"/*)
+    FILE "${_EXEC}/${PATH_INFO#/\[.\]}"
     ;;
   */)
     if [ -f "$_DATA/pages/$PATH_INFO/#page.md" \
@@ -77,6 +91,17 @@ case "${PATH_INFO}" in
       theme_404
     fi
     ;;
+  */"[edit]")
+    theme_editor "${PATH_INFO%\[edit\]}"
+    ;;
+  */"[login]")
+    [ "$USER_NAME" ] \
+    && REDIRECT "./" \
+    || theme_login
+    ;;
+  */"[register]")
+    theme_register
+    ;;
   */"[attachment]"/*)
     :  # TODO: Original attachment file
     ;;
diff --git a/pages/[wiki]/footer/#page.md b/pages/[wiki]/footer/#page.md
new file mode 100644 (file)
index 0000000..da2b20f
--- /dev/null
@@ -0,0 +1,3 @@
+----
+Shellwiki  
+Edit the Footer [here](/[wiki]/footer/[edit])
diff --git a/pages/[wiki]/header/#page.md b/pages/[wiki]/header/#page.md
new file mode 100644 (file)
index 0000000..b5d60ff
--- /dev/null
@@ -0,0 +1,8 @@
+# Shellwiki
+
+ * [Login]([login])
+ * [Register]([register])
+
+Edit the Header [here](/[wiki]/header/[edit])
+
+----
index 6370166017775241ed9691cfca7c23c78b7282d7..56b57aed24eb505669d742cca13fde2f9660ae3f 100755 (executable)
@@ -1,27 +1,74 @@
 #!/bin/sh
 
-theme_404(){
-  printf "%s\r\n" "Status: 404 Not Found"
+theme_head(){
+  printf '
+  <meta name="viewport" content="width=device-width"/>
+  <link rel="stylesheet" type="text/css" href="%s/[.]/cgilite/common.css">
+  ' "$_BASE"
+}
 
-  theme_page '/[404]/'
+theme_header(){
+  printf '<header>%s</header>' "$(wiki '[wiki]/header/')"
+}
+
+theme_footer(){
+  printf '<footer>%s</footer>' "$(wiki '[wiki]/footer/' ||echo No footer)"
 }
 
 theme_page(){
   local page="$1" title
   title="${page%/}"; title="${title##*/}"
 
+  # Important! Web Server response including newline newline
   printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
 
   cat <<-EOF
        <!DOCTYPE HTML>
        <html><head>
-         <meta name="viewport" content="width=device-width"/>
-         <link rel="stylesheet" type="text/css" href="$_BASE/[wiki]/cgilite/common.css">
+         $(theme_head)
          <title>$(HTML "${title}")</title>
        </head><body id="$(HTML "$page")">
-         <header></header>
+         $(theme_header)
          <main>$(wiki "$page" || printf 'Page not found')</main>
-         <footer></footer>
+         $(theme_footer)
        </body></html>
        EOF
 }
+
+theme_editor(){
+  local page="$1" title
+  title="${page%/}"; title="${title##*/}"
+
+  # Important! Web Server response including newline 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>
+            <textarea name=page>$(wiki_text "$page" |HTML)</textarea>
+            <button type=submit name=update value="$(HTML "$page")">Update</button>
+            <button type=submit name=cancel value="$(HTML "$page")">Cancel</button>
+          </form></main>
+         $(theme_footer)
+       </body></html>
+       EOF
+}
+
+theme_login(){
+  theme_page '[wiki]/login/'
+}
+
+theme_register(){
+  theme_page '[wiki]/register/'
+}
+
+theme_404(){
+  printf "%s\r\n" "Status: 404 Not Found"
+
+  theme_page '[wiki]/404/'
+}